我在php中创建一个登录页面。我想在成功登录后将用户重定向到自动页面。由于我使用pdo,因此我使用require_once来调用pdo.php。但是,这行代码阻止重定向指定的页面。如果我删除了require_once代码,我可以成功地返回到索引页后,我打cancle。下面的代码会带我到auto.php页Require_once阻止我重定向PHP
<?php
require_once "pdo.php";
require_once "bootstrap.php";
if (isset($_POST['cancel'])) {
// Redirect the browser to game.php
header("Location: index.php");
return;
}
$failure = false;
if (isset($_POST['email']) && isset($_POST['password']) ) {
if (strlen($_POST['email']) < 1 || strlen($_POST['password']) < 1) {
$failure = "User name and password are required";
}
else if (strpos($_POST['email'], '@')!== false)
{
$e = htmlentities($_POST['email']);
$p = htmlentities($_POST['password']);
$sql = "SELECT email FROM users
WHERE email = '$e'
AND password = '$p'";
echo "<p>$sql</p>\n";
$stmt = $pdo->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($row);
echo "-->\n";
if ($row === FALSE) {
echo "Incorrect password";
}
else {
header("Location: autos.php?name=".urlencode($_POST['email']));
return;
}
}
else
{
$failure = "Email must have an at-sign (@)";
}
}
?>
可能因为文件不存在,所以代码停止执行。 –
检查日志。什么是错误? –
您是否尝试过在if(isset($ _ POST ['cancel']))'后面使用'require_once'? – DrKey