{ "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 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> <\/p> Login<\/h1>