简体   繁体   English

如何从访问者浏览器中删除会话

[英]How Delete session from visitor browser

I have problem with session, I try unset($_SESSION) and session_unset() and session_destroy() session destroyed but still show in browser (cookie extension) 我的会话有问题,我尝试unset($_SESSION)session_unset()以及session_destroy()会话,但仍在浏览器中显示(cookie扩展)

I want remove it finality like session_start(['cookie_lifetime' => 10]) but I not want set a time, I want only remove it in a location on my php code, any idea? 我想像session_start(['cookie_lifetime' => 10])这样删除终结点,但我不想设置时间,我只想在我的php代码中的某个位置删除它,有什么想法吗?

My code here: 我的代码在这里:

<?php 
session_start();
$_SESSION['style'] = $style;
echo "Your style is : " . $style;
unset($_SESSION['style']);
session_destroy();

The session cookie stored in the browser simply contains a reference to the session ID on the server and does not contain any actual session data. 存储在浏览器中的会话cookie仅包含对服务器上会话ID的引用,并且不包含任何实际会话数据。 All of that is stored solely on the server and it would actually be a huge security issue if it were stored client-side. 所有这些都仅存储在服务器上,如果将其存储在客户端,则实际上将是一个巨大的安全问题。 If you delete the session on the server, this deletes all data stored on the server to do with that session and any attempt to re-authenticate using the old session ID will fail. 如果您删除服务器上的会话,这将删除服务器上与该会话有关的所有数据,并且任何使用旧会话ID进行重新身份验证的尝试都将失败。 If the browser sends an old session cookie back to the server after the session has been destroyed, it will simply be ignored by the server. 如果在会话被销毁后浏览器将旧的会话cookie发送回服务器,则服务器将简单地忽略它。 Therefore there is no need to delete the session cookie from the user's browser since this will be done automatically by the browser when the window is closed. 因此,无需从用户的浏览器中删除会话cookie,因为当关闭窗口时,浏览器会自动完成会话cookie。 The recommended way to kill a session is simply to do: 建议终止会话的简单方法是:

$_SESSION = array();

However, with that said, if you want to manually force the cookie to be deleted for whatever reason: 不过,无论如何,如果您出于任何原因要手动强制删除Cookie,请执行以下操作:

<?php 
session_start();
$_SESSION['style'] = $style;
echo "Your style is : " . $style;
unset($_SESSION['style']);

if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', -1,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}

session_destroy();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM