{ "key_pair_value_system": true, "answer_rating_count": "", "question_feedback_html": { "html_star": "", "html_star_feedback": "" }, "answer_average_rating_value": "", "answer_date_js": "2024-09-24T11:02:53-04:00", "answer_date": "2024-09-24 11:02:53", "is_docs_available": "", "is_excel_available": "", "is_pdf_available": "", "count_file_available": 0, "main_page": "student_question_view", "question_id": "12995955", "url": "\/study-help\/questions\/php-code-help-i-made-a-login-screen-and-all-12995955", "question_creation_date_js": "2024-09-24T11:02:53-04:00", "question_creation_date": "Sep 24, 2024 11:02 AM", "meta_title": "[Solved] PHP code help. I made a login screen and | SolutionInn", "meta_description": "Answer of - 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 | SolutionInn", "meta_keywords": "php,code,help,made,login,screen,steps,add,session,make,stay,logged", "question_title_h1": "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", "question_title": "PHP code help. I made a login screen and all the steps,", "question_title_for_js_snippet": "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 Login Login Username Password Login", "question_description": "
PHP code help.<\/p>
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?<\/p>
\/\/ Set the username and password for each account $accounts = array( 'admin' => 'admin', 'publisher' => 'publisher', 'customer' => 'customer' );<\/p>
\/\/ 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.'; } } ?><\/p>
<\/p>