我有一個名爲signin.php
的登錄頁面,用戶可以在其中輸入電子郵件和密碼。點擊提交按鈕,頁面指向connection_validate.php
。此頁面用數據庫驗證用戶輸入的數據。如果是註冊用戶,則該頁面指向calendar.php
。如果輸入的數據不正確,它應該重定向到signin.php
。如果輸入的數據是不正確的,我已經把餅乾這樣的:以編程方式清除cookie
//action to be done if e mail id and password matches with database records
if(mysql_num_rows($result)>0)
{
header('location:calendar.php');
}
//action to be done if e mail id and password does not matches with database records
else
{
setcookie('message','incorrect login data');
header('location:signin.php');
}
在signin.php,我已經寫了顯示警告的代碼,如果登錄信息不正確,這樣的:
<?php
include("include/minfooter.php");
if(isset($_COOKIE["message"]))
{
if(!($_COOKIE["message"]==" "))
{
echo "<script>
alert('Incorrect login information');
</script>";
setcookie("message"," ",time()-3600);
}
}
?>
我的問題是,如果我一次輸入了錯誤登錄數據,每次加載登錄頁面時都會顯示警報。如果我也按下從calendar.php的後退按鈕signin.php,警報開始顯示。我瞭解到問題出在cookie上。 Cookie尚未刪除。我該如何解決這個問題。
這是錯誤的,setcookie()設置一個HTTP頭,在你已經輸出內容到瀏覽器後不能放置。你的語法也是錯的。 –
更新了我的答案,現在它的100%正確 – user1911857
我說75%是正確的。你有if(isset($ _ COOKIE [「message」]))兩次,但它仍然不是正確的方法。 –