我今天正在建設我的網站,我意識到每次我去測試它,我必須保持登錄到我的網站我的帳戶,這將是正常的,除非我設置Cookie過期在30天內,出於某種原因,我認爲他們沒有正確地做好自己的工作,但不幸的是,我並沒有很多關於解決問題的知識,下面是在登錄時設置cookie的代碼,如果您需要更多信息,請告訴我。不保存帳戶登錄的Cookie
$encryptedID = base64_encode("g4enm2c0c4y3dn3727553$id");
setcookie("idCookie", $encryptedID, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days
setcookie("passCookie", $pass, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days
一些更多的代碼,它上面的(可以幫助)
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
// Pleae note: Adam removed all of the session_register() functions cuz they were deprecated and
// he made the scripts to where they operate universally the same on all modern PHP versions(PHP 4.0 thru 5.3+)
// Create session var for their raw id
$user_id = $row["user_id"];
$_SESSION['user_id'] = $user_id;
// Create the idx session var
$_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$id");
// Create session var for their username
$login_username = $row["login_username"];
$_SESSION['login_username'] = $login_username;
// Create session var for their password
$login_userpass = $row["login_password"];
$_SESSION['login_userpass'] = $login_userpass;
$sql_login = mysql_query("SELECT no_of_logins FROM users WHERE user_id='$user_id'");
$array = mysql_fetch_assoc($sql_login);
$no_of_logins = $array['no_of_logins'];
//$sql_login_check = mysql_num_rows($sql_login);
if($no_of_logins == "0"){
mysql_query("UPDATE users SET first_login=now() WHERE user_id='$user_id' LIMIT 1");
}
mysql_query("UPDATE users SET last_login=now() WHERE user_id='$user_id' LIMIT 1");
mysql_query("UPDATE users SET online = '1' WHERE user_id='$user_id' LIMIT 1");
mysql_query("UPDATE users SET no_of_logins = no_of_logins + 1 WHERE user_id='$user_id' LIMIT 1");
mysql_query("UPDATE system SET total_logins = total_logins + 1");
mysql_query("UPDATE system SET no_online = no_online + 1");
} // close while
// Remember Me Section
$encryptedID = base64_encode("g4enm2c0c4y3dn3727553$id");
setcookie("idCookie", $encryptedID, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days
setcookie("passCookie", $pass, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days
// All good they are logged in, send them to homepage then exit script
header("Location: profile.php");
exit();
} else { // Run this code if login_check is equal to 0 meaning they do not exist
$loginErrorMsg = "Incorrect login data, please try again";
$errorDisplay = '';
}
感謝您的任何和所有幫助
請正確縮進您的代碼,您的for循環在哪裏開始?未格式化的代碼使你看起來很粗心 –