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
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