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 even when I go to another page? What am I doing wrong? I also need it to log out when I close the window.
// 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
Lastly, this part " In addition, if a session exists, the footer of each web page should have a logout link. When the logout link is clicked, the user should be asked to confirm or cancel their logout. Once confirmed, the session should be destroyed." of my assignment, I have in a file called LogOutQuestion.php and then goes to Logout.php. But isn't working in the footer. The code is right it just isn't showing the Logout hyper link because the session isn't holding for whoever "signedin"
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
