【发布时间】:2023-02-16 18:39:22
【问题描述】:
我已经为我的自定义网站构建了一个简单的登录系统,我在我的数据库中创建了一个表,我在 phpmyadmin 中存储了用户名和密码,现在我意识到在 412 记录之后,sql 查询无法找到用户名和密码的匹配项。我正在尝试搜索整个表格,但它就停在那里。
``
// Define $username and $password
$username = $_POST['username'];
$password = $_POST['password'];
// mysqli_connect() function opens a new connection to the MySQL server.
$conn = mysqli_connect("******", "*******", "*******", "********");
// SQL query to fetch information of registered users and finds user match.
$query = "SELECT username, password from login where online=1 AND username='" . $username . "' AND password='" . $password . "' LIMIT 1";
// To protect MySQL injection for Security purpose
$stmt = $conn->prepare($query);
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$stmt->bind_result($username, $password);
$stmt->store_result();
if($stmt->fetch()){ //fetching the contents of the row {
$_SESSION['login_user'] = $username; // Initializing Session
header("location: user_profile"); // Redirecting To Profile Page
}
``
【问题讨论】:
-
你在那里处理准备好的陈述完全错误。您仍然直接将用户名和密码插入到查询中,而不是使用占位符。 (想知道这不会首先爆炸,当您尝试将参数绑定到它时?)而且您显然仍在将密码存储为纯文本,这也是糟糕的.