提供的 PHP 代码遇到了几个阻碍其实现的问题功能:
以下内容修订后的代码解决了已发现的问题,并提供了更安全的会员专用页面登录系统:
<?php session_start(); error_reporting(0); $servername = "localhost"; $username = "root20"; $password = "jjewett38"; $db = "vws"; // Create connection $total = $data = 0; $conn = new mysqli($servername, $username, $password, $db); // Check connection if ($conn->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(); ?>
以上是如何用 PHP 安全地实现会员专用页面登录系统?的详细内容。更多信息请关注PHP中文网其他相关文章!