Ok, I goofed around with this some more ;D ;D ;D :
[php]<?php
// Start the session
/* Turn on error reporting */
ini_set(‘display_errors’, 1);
ini_set(‘display_startup_errors’, 1);
if (filter_input(INPUT_SERVER, ‘SERVER_NAME’, FILTER_SANITIZE_URL) == “localhost”) {
error_reporting(-1); // -1 = on || 0 = off
} else {
error_reporting(0); // -1 = on || 0 = off
}
session_start();
if (!isset($_SESSION[‘remember_me’])) {
$_SESSION[‘remember_me’] = false; // Remember Me:
}
$user_record = \NULL; // Initial $user_record variable to NULL:
$error = NULL;
/*
- Dummy Records of users.
*/
$data = [
0 => [
“username” => “[email protected]”,
“password” => “DetroitTigers”
],
1 => [
“username” => “[email protected]”,
“password” => “ClevelandIndians”
],
2 => [
“username” => “[email protected]”,
“password” => “NewYorkYankees”
],
3 => [
“username” => “[email protected]”,
“password” => “HoustonAstros”
]
];
//echo “
” . print_r($data, 1) . “
”;
/*
/*
- Check to see if user has submitted form
*/
$action = filter_input(INPUT_POST, ‘action’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if (isset($action) && $action === ‘login’) {
/*
* Get User’s inputs
*/
$username = htmlspecialchars($_POST[‘username’]);
$password = htmlspecialchars($_POST[‘password’]);
$remember_me = htmlspecialchars($_POST[‘remember_me’]);
if ($remember_me === 'yes') {
$_SESSION['remember_me'] = true;
}
//echo $username . "<br>";
/*
* Check to see if username is in dummy records,
* if it is then store that user's stored record into the $user_record which
* creates an array.
*/
foreach ($data as $records) {
if (in_array($username, $records)) {
$user_record = $records;
}
}
/*
* If is an array then check user's password against the $user_record['password'] to
* see if it matches.
*/
if (is_array($user_record)) {
if (isset($password) && password_verify($password, $user_record['password'])) {
//echo "<pre>" . print_r($user_record, 1) . "</pre>";
$_SESSION['status'] = $user_record['username'];
header("Location: login_01.php");
exit();
} else {
$error = "Sorry either the username or password is incorrect, please re-enter<br>";
}
} else {
$error = "Sorry either the username or password is incorrect, please re-enter<br>";
}
}
if (isset($action) && $action === “logout”) {
// Use both for compatibility with all browsers
// and all versions of PHP.
session_unset();
session_destroy();
header(“Location: login_01.php”);
exit();
}
?>
servicemontør.dk
* {
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
}
.login, .logout {
width: 100%;
max-width: 800px;
height: auto;
background-color: lightblue;
padding: 20px;
margin: 20px auto;
}
.error {
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
font-size: 1.4em;
color: red;
}
form#login, form#logout {
width: 100%;
max-width: 600px;
height: auto;
background-color: #F9F6F0;
padding: 10px;
margin: 10px auto;
}
form#login fieldset {
border: 2px solid #2e2e2e;
padding: 20px;
}
form#login legend {
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
font-size: 1.8em;
padding: 0 5px;
}
form#login label, form#logout label {
float: left;
display: block;
width: 100%;
max-width: 150px;
height: 30px;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.2em;
line-height: 30px;
text-transform: capitalize;
}
form#logout label {
display: inline-block;
line-height: 40px;
max-width: 340px;
}
form#login input[type=text], form#login input[type=password] {
outline: none;
clear: right;
display: block;
width: 100%;
max-width: 250px;
height: 30px;
padding: 0 5px;
margin-bottom: 10px;
}
form#login input[type=checkbox] {
width: 30px;
height: 20px;
}
form#login label.remember_me {
display: block;
float: left;
width: 90px;
height: 50px;
line-height: 30px;
text-transform: none;
}
form#login input[type=submit], form#logout input[type=submit] {
cursor: pointer;
border: none;
outline: none;
background-color: #2e2e2e;
clear: both;
display: block;
width: 100%;
max-width: 100px;
height: 40px;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.4em;
color: #fff;
text-transform: capitalize;
}
form#logout input[type=submit] {
clear: none;
}
form#login input[type=submit]:hover, form#logout input[type=submit]:hover {
background-color: blue;
}
<?php if (!$_SESSION['remember_me'] || $error) { ?>
<?php echo ($error) ? $error : NULL; ?>
Servicemontør.dk
email address
password
Husk mig!
<?php } else { ?>
You are login as <?= $_SESSION['status']; ?>!
<?php } ?>
[/php]