Last active
January 6, 2022 14:11
-
-
Save CuzImBisonratte/a31289d660d52ecb2081c6760f67ed26 to your computer and use it in GitHub Desktop.
Login Skript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"testaccount": "password", | |
"testaccount2": "password2" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="login"> | |
<!-- Header --> | |
<h1>Login</h1> | |
<!-- The form --> | |
<form action="login.php" method="post"> | |
<!-- Username field --> | |
<label for="username"> | |
<i class="fas fa-user"></i> | |
</label> | |
<input type="text" name="username" placeholder="Nutzername" id="username" required> | |
<!-- Password field --> | |
<label for="password"> | |
<i class="fas fa-lock"></i> | |
</label> | |
<input type="password" name="password" placeholder="Passwort" id="password" required> | |
<!-- Login-knopf --> | |
<input type="submit" value="Login"> | |
</form> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Check if the user is logged in | |
// If so, redirect to ../index.php | |
if (isset($_SESSION['loggedin'])) { | |
header('Location: ../index.php'); | |
exit; | |
} | |
// Start sessions | |
session_start(); | |
// Include the accounts.json file | |
$accounts = file_get_contents('accounts.json'); | |
// Decode the accounts.json file | |
$accounts = json_decode($accounts, true); | |
// Get $_POST data | |
// There are $username and $password | |
$username = $_POST['username']; | |
$password = $_POST['password']; | |
// Go through the accounts.json file | |
// Check if the username and password match | |
foreach ($accounts as $account) { | |
if ($account['username'] == $username && $account['password'] == $password) { | |
// If so, set the loggedin session variable | |
$_SESSION['loggedin'] = true; | |
// And redirect to ../index.php | |
header('Location: ../index.php'); | |
exit; | |
} else { | |
// Reload the login.html page | |
header('Location: index.html'); | |
exit; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment