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.';

}

}

?>

Log In

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:

PHP HTML code. I am having trouble getting the rest of the

site to remember who logged in once someone does. I thought I

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!