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

Login<\/title> <\/head> <body> <h1>Login<\/h1> <?php if (isset($error)): ?> <p><?php echo $error; ?><\/p> <?php endif; ?> <form method=\"post\" action=\"\"> <label for=\"username\">Username:<\/label> <input type=\"text\" id=\"username\" name=\"username\"> <label for=\"password\">Password:<\/label> <input type=\"password\" id=\"password\" name=\"password\"> <button type=\"submit\">Login<\/button> <\/form> <\/body> <\/html><\/p>", "transcribed_text": "", "related_book": { "title": "Understanding Oracle APEX 5 Application Development", "isbn": "1484209893, 9781484209899", "edition": "2nd Edition", "authors": "Edward Sciore", "cover_image": "https:\/\/dsd5zvtm8ll6.cloudfront.net\/si.question.images\/book_images\/2022\/02\/61fa2d446ce2f_53961fa2d43cfdde.jpg", "uri": "\/textbooks\/understanding-oracle-apex-5-application-development-2nd-edition-9781484209899", "see_more_uri": "" }, "question_posted": "2024-09-24 11:02:53", "step_by_step_answer": "The Answer is in the image, click to view ...", "students_also_viewed": [ { "url": "\/study-help\/international-human-resource-management\/describe-your-colleges-culture-is-it-strong-or-weak-are-2105967", "description": "Describe your colleges culture. Is it strong or weak? Are there any good slogans and\/or symbols that help convey your colleges culture? Give at least one new way (slogans\/ symbols, etc.) to promote...", "stars": 0 }, { "url": "\/in-a-random-sample-of-400-people-purchasing-state-lottery", "description": "In a random sample of 400 people purchasing state lottery tickets, 172 sample members were women. Test the null hypothesis that half of all purchasers are women.", "stars": 3 }, { "url": "\/study-help\/questions\/php-code-help-i-made-a-login-screen-and-all-12995955", "description": "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", "stars": 3 }, { "url": "\/study-help\/questions\/why-is-budgeting-important-for-a-firm-should-a-firms-4148226", "description": "Why is budgeting important for a firm? Should a firm's budget ever be violated or exceeded? Why?", "stars": 3 }, { "url": "\/study-help\/questions\/question-1-13-pts-read-the-following-and-use-it-4878438", "description": "Question 1 (13 pts) Read the following and use it to answer the following questions: James owns a factory that produces fuel from bio waste and sells the fuel to the agricultural industry. He holds a...", "stars": 3 }, { "url": "\/study-help\/questions\/1breakeven-point-algebraic-and-graphicalfine-leather-enterprises-sells-its-single-1358046", "description": "1)Breakeven point: Algebraic and graphicalFine Leather Enterprises sells its single product for $129.00 per unit. The firm's fixed operating costs are $473,000 annually, and its variable operating...", "stars": 3 }, { "url": "\/study-help\/questions\/13-jose-is-35-years-old-and-makes-40000-per-1358340", "description": "13. Jose is 35 years old, and makes $40,000 per year. If he dies, how much would the beneficiaries of his life insurance policy receive if they can get by on 75% of his income?", "stars": 3 }, { "url": "\/study-help\/questions\/cookie-business-in-this-project-you-will-be-opening-your-1358415", "description": "Cookie Business In this project, you will be opening your own specialty cookie company to see how product costing methods and changes in production affect business decisions. You will be creating a...", "stars": 3 }, { "url": "\/study-help\/questions\/the-probability-of-event-a-is-50-the-probability-of-1359220", "description": "The probability of event \"A\" is 50%. The probability of event \"B\" is 20%. \"A\" and \"B\" are two independent events. What is the probability of observing \"A\" and \"B\"?", "stars": 3 } ], "next_back_navigation": { "previous": "\/study-help\/questions\/find-the-maximum-value-and-minimum-value-in-milestracker-assign-12995954", "next": "\/study-help\/questions\/are-two-related-12995956" }, "breadcrumbs": [ { "name": "Study help", "link": "https:\/\/www.solutioninn.com\/study-help\/questions-and-answers" }, { "name": "Computer Science", "link": "https:\/\/www.solutioninn.com\/study-help\/questions-and-answers\/computer-science" }, { "name": "Databases", "link": "https:\/\/www.solutioninn.com\/study-help\/questions\/computer-science-databases" }, { "name": "PHP code help. I made a login screen and all the steps,", "link": "https:\/\/www.solutioninn.com\/study-help\/questions\/php-code-help-i-made-a-login-screen-and-all-12995955" } ], "skill_details": { "skill_id": "656", "skill_name": "Databases", "parent_id": "8" } }