我在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