提供的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中文網其他相關文章!