Question
PHP HTML code. I am having trouble getting the rest of the site to remember who logged in once someone does. I thought I was
PHP HTML code. I am having trouble getting the rest of the site to remember who logged in once someone does. I thought I was correct on calling the access_level as the username/ But idk because when I go to click to another site on my website it doesn't show who is logged in.
This is my login.php
session_start();
// Set the username and password for each account
$accounts = array(
'admin' => 'admin',
'publisher' => 'publisher',
'customer' => 'customer'
);
// Check if the user has submitted the login form
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
// Check if the username and password match an account
if (isset($accounts[$username]) && $accounts[$username] == $password) {
// Set the access level in the session
$_SESSION['access_level'] = $username;
// Redirect to the appropriate page
if ($username == 'admin') {
header('Location: admin.php');
exit();
} else if ($username == 'publisher') {
header('Location: publisher.php');
exit();
} else if ($username == 'customer') {
header('Location: customer.php');
exit();
}
} else {
$error = 'Invalid username or password.';
}
}
?>
Input your login information
The footer.php has the logout information init and that is where I would like it to remember the username and have the logout option available, if you catch my drift.
This is my footer.php
Validated by:
if (!isset($_SESSION['access_level'])) {
echo " USER NOT LOGGED IN. Log In here";
} else echo " User: {$_SESSION['access_level']}";
if (isset($_SESSION['access_level'])) {
echo " Logout";
}
echo " ";
echo " ";
echo "Last modified:";
$timestamp = filemtime(__FILE__);
$date_time = new DateTime();
$date_time->setTimezone(new DateTimeZone("America/New_York"));
$date_time->setTimestamp($timestamp);
echo $date_time->format("F j Y g:i a.");
?>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started