{ "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-23T00:07:49-04:00", "answer_date": "2024-09-23 00:07:49", "is_docs_available": "", "is_excel_available": "", "is_pdf_available": "", "count_file_available": 0, "main_page": "student_question_view", "question_id": "12636661", "url": "\/study-help\/questions\/how-do-i-fix-my-cookie-so-it-only-lets-12636661", "question_creation_date_js": "2024-09-23T00:07:49-04:00", "question_creation_date": "Sep 23, 2024 12:07 AM", "meta_title": "[Solved] how do i fix my cookie so it only lets me | SolutionInn", "meta_description": "Answer of - how do i fix my cookie so it only lets me access hw1.php unless my login is correct. and if incorrect hw1.php cannot b | SolutionInn", "meta_keywords": "fix,cookie,lets,access,hw1,php,login,correct,incorrect,accessed,redirects,hwloginphp", "question_title_h1": "how do i fix my cookie so it only lets me access hw1.php unless my login is correct. and if incorrect hw1.php cannot be accessed", "question_title": "how do i fix my cookie so it only lets me access", "question_title_for_js_snippet": "how do i fix my cookie so it only lets me access hw1 php unless my login is correct and if incorrect hw1 php cannot be accessed and redirects to hwlogin php hw1login php code Login Login Username Password hw1 php code Protected Page Welcome to the protected page", "question_description": "

how do i fix my cookie so it only lets me access hw1.php unless my login is correct. and if incorrect hw1.php cannot be accessed and redirects to hwlogin.php<\/p>

hw1login.php<\/p>

code:<\/p>

\/\/ Connect to the database $conn = new mysqli('localhost', '', '', ''); if ($conn->connect_error) { die(\"Connection failed: \" . $conn->connect_error); }<\/p>

\/\/ If the form has been submitted if ($_SERVER['REQUEST_METHOD'] == 'POST') { \/\/ Get the username and password from the form $username = $_POST['username']; $password = $_POST['password'];<\/p>

\/\/ Prepare the SQL query to check if the user exists $stmt = $conn->prepare('SELECT id FROM user WHERE username = ? AND password = ?'); $stmt->bind_param('ss', $username, $password); $stmt->execute(); $stmt->store_result();<\/p>

\/\/ If the user exists, set a cookie named \"user\" and redirect to the hw1.php page if ($stmt->num_rows > 0) { $stmt->bind_result($id); $stmt->fetch(); setcookie('userid', time() + (86400 * 30), \"\/\"); header('Location: week6.php'); exit; } else { $error = 'Incorrect username or password'; } } ?><\/p>

Login<\/title> <\/head> <body> <h1>Login<\/h1> <?php if (isset($error)) { ?> <p><?php echo $error; ?><\/p> <?php } ?> <form method=\"post\"> <label>Username:<\/label> <input type=\"text\" name=\"username\"> <label>Password:<\/label> <input type=\"password\" name=\"password\"> <input type=\"submit\" value=\"Login\"> <\/form> <\/body> <\/html><\/p> <p>hw1.php<\/p> <p>code:<\/p> <p><?php<\/p> <p>\/\/ Start the session<\/p> <p>session_start();<\/p> <p> <\/p> <p>\/\/ If the user is not logged in, redirect to the login page<\/p> <p>if (!isset($_COOKIE['userid'])) {<\/p> <p>header('Location: hwlogin.php');<\/p> <p>exit;<\/p> <p>}<\/p> <p>?><\/p> <p> <\/p> <p><!DOCTYPE html><\/p> <p><html><\/p> <p><head><\/p> <p><title>Protected Page<\/title><\/p> <p><\/head><\/p> <p><body><\/p> <p><h1>Welcome to the protected page<\/h1><\/p> <p><\/body><\/p> <p><\/html><\/p>", "transcribed_text": "", "related_book": { "title": "Implementing Ai And Machine Learning For Business Optimization", "isbn": "B0CPQJW72N, 979-8870675855", "edition": "1st Edition", "authors": "Robert K Wiley", "cover_image": "https:\/\/dsd5zvtm8ll6.cloudfront.net\/si.question.images\/book_images\/2024\/01\/65a236fecbd17_72665a236fec7654.jpg", "uri": "\/textbooks\/implementing-ai-and-machine-learning-for-business-optimization-1st-edition-979-8870675855-198440", "see_more_uri": "\/textbooks\/computer-science-adobe-freehand-2397" }, "question_posted": "2024-09-23 00:07:49", "step_by_step_answer": "The Answer is in the image, click to view ...", "students_also_viewed": [ { "url": "\/study-help\/business-statistics-for-contemporary\/a-determine-the-number-of-factors-k-the-number-of-2098470", "description": "a. Determine the number of factors, k, the number of levels, l, and the number of replicates, nR.", "stars": 0 }, { "url": "\/moonstruck-company-manufactures-a-reservation-system-with-an-estimated-economic", "description": "Moonstruck Company manufactures a reservation system with an estimated economic life of 12 years and leases it to National Airlines for a period of 10 years. The normal selling price of the equipment...", "stars": 3 }, { "url": "\/study-help\/questions\/how-do-i-fix-my-cookie-so-it-only-lets-12636661", "description": "how do i fix my cookie so it only lets me access hw1.php unless my login is correct. and if incorrect hw1.php cannot be accessed and redirects to hwlogin.php hw1login.php code: Login Login Username:...", "stars": 3 }, { "url": "\/study-help\/questions\/identify-the-conclusion-in-the-following-argument-if-the-green-2701931", "description": "Identify the conclusion in the following argument. If the Green Party ever wins significant power in the United States, the economy would be crippled. After all, they have repeatedly made it clear...", "stars": 3 }, { "url": "\/study-help\/questions\/justify-whether-or-not-you-believe-that-penalty-enhancements-should-1093473", "description": "Justify whether or not you believe that Penalty Enhancements should attach to crimes based on hate or bias?", "stars": 3 }, { "url": "\/study-help\/questions\/the-company-ceo-of-a-heavily-indebted-company-considers-taking-3260726", "description": "The company CEO of a heavily indebted company considers taking on a risky negative NPV project. In practice, the debtholders can best prevent this through 1 point a haircut. monitoring. increasing...", "stars": 3 }, { "url": "\/study-help\/questions\/3-how-do-guss-demands-fit-into-the-category-of-1060781", "description": "3. How do Gus's demands fit into the category of expecting Karen to exhibit strong organizational citizenship behavior?", "stars": 3 }, { "url": "\/study-help\/questions\/on-december-31-2010-gold-company-purchases-80-of-the-1091849", "description": "On December 31, 2010, Gold Company purchases 80% of the common stock of Silver Corp. for its underlying book value of $480,000. On that date, the fair value of non-controlling interest was equal to...", "stars": 3 }, { "url": "\/study-help\/questions\/question-8-of-50-question-id-1158320-registered-principal-jane-1056091", "description": "Question #8 of 50 Question ID: 1158320 Registered principal Jane has just received a recommendation from Charlotte for the purchase of a deferred variable annuity for Charlotte's client, William....", "stars": 3 }, { "url": "\/study-help\/fundamentals-of-human-resource-management\/promotion-by-seniority-salary-bands-have-low-differentials-in-japan-2116280", "description": "Promotion by seniority. Salary bands have low differentials in Japan at the beginning of the career, and promotion by seniority reflects a step-by-step approach, and a group orientation. European...", "stars": 3 }, { "url": "\/study-help\/fundamentals-of-human-resource-management\/1-in-view-of-the-changing-context-within-which-shell-2116268", "description": "1 In view of the changing context within which Shell operates, how is it possible to reconcile the need to be flexible and maintain an open market system for selecting expatriate managers for...", "stars": 3 }, { "url": "\/study-help\/fundamentals-of-human-resource-management\/1-are-there-high-failure-rates-among-expatriates-how-do-2116271", "description": "1 Are there high failure rates among expatriates? How do these differ from one home country to another, one host country to another, and from one company to another?", "stars": 3 } ], "next_back_navigation": { "previous": "\/study-help\/questions\/in-an-organization-there-are-four-branches-namely-a-12636660", "next": "\/study-help\/questions\/consider-the-nfa-with-epsilon-transitions-that-accepts-the-language-12636662" }, "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": "how do i fix my cookie so it only lets me access", "link": "https:\/\/www.solutioninn.com\/study-help\/questions\/how-do-i-fix-my-cookie-so-it-only-lets-12636661" } ], "skill_details": { "skill_id": "656", "skill_name": "Databases", "parent_id": "8" } }