The provided PHP code encounters several issues that hinder its functionality:
The following revised code addresses the identified issues and provides a more secure member-only page login system:
connect_error) { die("Connection failed: " . $conn->connect_error); } // Prepare statement for user authentication $sql_auth = $conn->prepare("SELECT * FROM users WHERE username = ? AND password = ?"); $sql_auth->bind_param("ss", $_POST['uname'], $_POST['pss']); $sql_auth->execute(); $result_auth = $sql_auth->get_result(); // Authenticate user if ($result_auth->num_rows > 0) { $user = $result_auth->fetch_assoc(); $correct = TRUE; } else { $correct = FALSE; } // Generate token if ($correct === TRUE) { $hex = bin2hex(random_bytes(3)); $_SESSION['auth'] = $hex; $_SESSION['logstat'] = TRUE; } // Close connection $conn->close(); ?>
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3