<form action=userLogin.php method=post>
<div id="login">
<div id="submit" class="h">Log In</div>
Email
<br>
<input id="email" name="email" type="email" required>
<br>
Password
<br>
<input name="pass" type="password" required=required><br>
<a href="recover.php">Forgot your password</a><br>
<div id="submit">
<input type="checkbox"> Remember
<div id="h">
<input type="submit" value="Log in"></div>
</div>
</div>
<?php
if (empty($_POST['pass']) == false) {
$uname = $_POST['email'];
$pass = $_POST['pass'];
include("config.php");
$query = $mysqli->query("SELECT * FROM user WHERE email='$uname' AND password='$pass'");
$numrows = mysqli_num_rows($query);
while ($row = mysqli_fetch_array($query)) {
if ($numrows == 0) {
?>
<script>
$(document).ready(function () {
$("#alert").fadeIn();
});</script>
<?php
}
else {
$id = $row[id];
setcookie('userId', $id);
}
}
}
?>
这是我的代码,它获取用户数据并检查用户是否存在并在用户的浏览器上设置 cookie。当我检查 cookie 是否已设置时,我只能看到 phpMyAdmin cookie 而不是我的 userId cookie。您可以看到屏幕截图,浏览器卡住并自动关闭但是当我使用setcookie('userId','$id');
cookie 编辑 setcookie 函数时,它的值是%24id
[$ ID]。那么如何在变量 $row[id] 的值中设置 cookie 是我的电脑或服务器或我的代码的错误?当我在没有 qoutes 的情况下使用带有 $id 的 chrome 时,错误来了This webpage is not available The webpage at localhost/mysite/mysite/userLogin.php might be temporarily down or it may have moved permanently to a new web address