如何从一个php会话注销 - session_destroy似乎不够 [英] how to logout from a php session - session_destroy doesn't seem to be enough

查看:193
本文介绍了如何从一个php会话注销 - session_destroy似乎不够的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习PHP和使用会话。我看到关于在注销时使用session_destroy的例子,但是我在php文档中看到这样:

I'm trying to learn PHP and using sessions. I seen examples about using session_destroy on logout, but I see this in the php documentation:


为了完全终止会话,记录用户出去,会话ID也必须被取消设置。如果使用cookie来传播会话ID(默认行为),那么必须删除会话cookie。

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.

因此注销后需要做什么?

so what does one need to do upon logout ?

推荐答案

有一个例子回答你刚刚引用的段落下面的问题:
http://php.net/manual/en/function.session-destroy.php

There's, like, an example answering your question just below the paragraph you just quoted: http://php.net/manual/en/function.session-destroy.php


示例#1使用$ _SESSION破坏会话



Example #1 Destroying a session with $_SESSION

<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}

// Finally, destroy the session.
session_destroy();
?>


这篇关于如何从一个php会话注销 - session_destroy似乎不够的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆