Question: PHP code help. I made a login screen and all the steps, but how do I add in the session code to make it stay

PHP code help.

I made a login screen and all the steps, but how do I add in the session code to make it stay logged in? What am I doing wrong?

// 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.'; } } ?>

Login

Login

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!