【发布时间】:2014-11-21 20:37:17
【问题描述】:
当我提交密码和用户名时,php的配置文件是空白的。为了知道问题是什么,我回显了所有错误消息。在 $count 查询中,我写了一条错误消息,即“电子邮件和密码不匹配”。
if($count===1)
{
$_SESSION['logged_in'] = true;
header("location:index.php");
exit;
}
else
{
echo "the emailand password doesn't match.";
exit;
}
当我重新提交登录表单时,它会打印出回显“用户名和密码不匹配”。我在表格中检查了密码和用户名是否正确。
这是完整的脚本:
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", true);
error_reporting(-1);
ini_set('display_errors', 'On');
$mysqli = new mysqli("com", "ih", "th", "rcser");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$myemail= $_POST['myemail'];
$mypassword= $_POST['mypassword'];
$sql= "SELECT * FROM user WHERE myemail = ? and mypassword = ?";
/* create a prepared statement */
if ($stmt = $mysqli->prepare($sql)) {
/* bind parameters for markers */
$stmt->bind_param("ss", $myemail, $mypassword);
/* execute query */
$stmt->execute();
/* count */
$count = $stmt->num_rows;
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
if($count===1){
$_SESSION['logged_in'] = true;
header("location:index.php");
exit;
}
else
{
echo "the email and password doesn't match.";
exit;
}
ob_end_flush();
?>
【问题讨论】:
-
我在任何地方都看不到 $username 设置。另外,不应该算 if($count == 1) not ===
-
应该怎样设置$username?我已经编辑了这个问题。好吧,如果 === 是问题,我会检查它。
-
==vs.===如果类型匹配应该不是问题 -
您设置的 $username 不存在。你需要用一些东西来设置它,也许是电子邮件。你在检查什么。不过很容易绕过那个登录脚本。
-
很遗憾,这不是问题。