這裏,其中用戶登錄去了。我似乎無法能夠註銷當我登錄「記住我」不積極......如何註銷,並不能正常註銷用PHP?
while($user = $stmt->fetch(PDO::FETCH_ASSOC)) {
$passwordDB = $user['mypassword'];
$email = $user['email_address'];
$userid = $user['user_id'];
}
if ($remember_me == "true"){ // Create a Cookie if remember_me is active
$expire = time()+60*60*24; // Valid for only 1 day
setcookie("cookie_username", $username, $expire, "/");
setcookie("cookie_email", $email, $expire, "/");
setcookie("cookie_userid", $userid, $expire, "/");
} else if ($remember_me == "false") { // Only create a session if remember_me is not active
session_start(); // cannot logout if i put it here
$_SESSION['session_userid'] = $userid;
$_SESSION['session_username'] = $username;
$_SESSION['session_email'] = $email;
}
我的PHP代碼註銷
<?php
require_once 'mydatabase.php';
$_SESSION = array();
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 86400,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
?>
當我的'記住我'選中時,我可以正確註銷。 問題解決:我不小心抹去我session_start()
在我註銷的頂部,忘了把它放回
您可以張貼在您檢查,如果用戶登錄的代碼?我假設你需要重置所有字段的cookie值。使用瀏覽器的網絡開發工具來查看設置了哪些值 – BNT