我在登錄頁面遇到問題。當我按下登錄按鈕時,只有在記住我複選框被選中的情況下,我才能進入用戶面板。如果它沒有被檢查,那麼它保持登錄頁面。我無法弄清楚錯誤。登錄頁面錯誤
include("Database/database.php");
session_start();
if(isset($_COOKIE['username']) and isset($_COOKIE['passcode'])) {
$username = $_COOKIE['username'];
$passcode = $_COOKIE['passcode'];
$_SESSION['name'] = $username;
$_SESSION['pwd'] = $passcode;
header("Location: useraccount.php"); /*Checks if cookies are set then takes me directly to useraccount.php */
} else if (isset($_POST['login'])) {
$username = $_POST['username'];
$userpwd = $_POST['userpwd'];
$rem = $_POST['remember'];
$query = "SELECT * FROM login WHERE userName = '$username' AND Password = '$userpwd'";
$result = mysqli_query($link, $query);
$row = mysqli_num_rows($result);
if ($row > 0) {
$_SESSION['name'] = $username;
$_SESSION['pwd'] = $userpwd;
if (isset($_POST['remember'])) /*if remember me checkbox is checked than it set cookies and it takes me to useraccount.php page. But if I donot check the check box (remember me) than I am where I am on login page. */
{
setcookie("username", $username, time()+60*60*7);
setcookie("passcode", $userpwd, time()+60*60*7);
}
header("Location: useraccount.php"); /* It should procees to useracocunt.php page but it stays on login.php*/
} else {
header("Location: login.php"); /*Used this for testing purpose if login fails it takes me to homepage which is working fine*/
}
mysqli_close($link);
}
}
嗨,我已經做到了,它並沒有幫助,你看到當記得是一個例外,如果用戶檢查它設置了Cookie,他仍然應該登錄到他的帳戶。 –
我添加if語句來檢查會話是否已設置,因此缺少該語句。請嘗試添加此。 –
但請確保在useraccount.php中,您不僅查看cookie,還查看會話... –