PHP - 无法结束会话
PHP - Can't end session
登录后我的网站上有一个 link,它指向 "index.php?logout=yes",然后在我的 index.php 中有以下代码:
if ($_GET['logout'] == "yes") {
session_unset();
unset($_SESSION);
session_destroy();
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
$_SESSION = array();
$_SESSION = [];
}
知道为什么它会让您保持登录状态但不会结束会话吗?
这是你的第一行代码吗index.php如果是使用
header('Location: /');
而不是刷新的元标记
请检查:session_destroy
In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.
试试这个
session_unset(); //or unset($_SESSION);
session_destroy();
session_commit(); // or session_write_close();
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);
header('location: index.php');
注销后,将用户重定向到主页(例如)
并且始终在使用之前启动会话
<php
session_start();
if ($_GET['logout'] == "yes") {
session_unset();
session_destroy();
session_write_close();
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);
header('location: index.php');
}
public 函数注销() {
$this->session->set_userdata(array(
'user_id' => '',
'fname' => '',
'lname' => '',
'gender' => '',
'username' => '',
'user_comp_id' => '',
'user_role' => '',
'validated' => false,
'plan_name' => '',
'plan_restriction' => '',
'module_leave_bank' => '',
'module_custom_logo' => '',
'module_bulk_import' => '',
'module_custom_rules' => '',
'module_reports_download' => '',
'module_integrations' => '',
'module_chat_support' => '',
'module_phone_support' => '',
'users_limit' => '',
'leave_policies_limit' => '',
'ous_limit' => '',
'sub_ous_limit' => '',
'leave_requests_limit' => '',
'holidays_limit' => '',
'users_count' => '',
'leave_policies_count' => '',
'ous_count' => '',
));
$cookies_id = $this->input->cookie('ci_session', TRUE);
// $this->db->delete('user_logged_in',array('cookie' => $cookies_id)); // delete the cookies in database
$this->session->sess_destroy();
redirect('login', 'refresh');
}
登录后我的网站上有一个 link,它指向 "index.php?logout=yes",然后在我的 index.php 中有以下代码:
if ($_GET['logout'] == "yes") {
session_unset();
unset($_SESSION);
session_destroy();
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
$_SESSION = array();
$_SESSION = [];
}
知道为什么它会让您保持登录状态但不会结束会话吗?
这是你的第一行代码吗index.php如果是使用 header('Location: /'); 而不是刷新的元标记
请检查:session_destroy
In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.
试试这个
session_unset(); //or unset($_SESSION);
session_destroy();
session_commit(); // or session_write_close();
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);
header('location: index.php');
注销后,将用户重定向到主页(例如)
并且始终在使用之前启动会话
<php
session_start();
if ($_GET['logout'] == "yes") {
session_unset();
session_destroy();
session_write_close();
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);
header('location: index.php');
}
public 函数注销() {
$this->session->set_userdata(array(
'user_id' => '',
'fname' => '',
'lname' => '',
'gender' => '',
'username' => '',
'user_comp_id' => '',
'user_role' => '',
'validated' => false,
'plan_name' => '',
'plan_restriction' => '',
'module_leave_bank' => '',
'module_custom_logo' => '',
'module_bulk_import' => '',
'module_custom_rules' => '',
'module_reports_download' => '',
'module_integrations' => '',
'module_chat_support' => '',
'module_phone_support' => '',
'users_limit' => '',
'leave_policies_limit' => '',
'ous_limit' => '',
'sub_ous_limit' => '',
'leave_requests_limit' => '',
'holidays_limit' => '',
'users_count' => '',
'leave_policies_count' => '',
'ous_count' => '',
));
$cookies_id = $this->input->cookie('ci_session', TRUE);
// $this->db->delete('user_logged_in',array('cookie' => $cookies_id)); // delete the cookies in database
$this->session->sess_destroy();
redirect('login', 'refresh');
}