Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

10. Are you a. a leader? b. a follower? _______

Answered: 1 week ago

Question

What did they do? What did they say?

Answered: 1 week ago