PHP 中的 session_unset() 和 session_destroy() 有什么区别? [英] What is the difference between session_unset() and session_destroy() in PHP?

查看:37
本文介绍了PHP 中的 session_unset() 和 session_destroy() 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 php.net 文档:

session_destroy — 销毁所有数据注册到会话

session_destroy — Destroys all data registered to a session

session_unset — 免费所有会话变量

session_unset — Free all session variables

我的三部分问题是:

这两个功能看起来很相似.
两者之间的真正区别是什么?

The two functions seem very similar.
What is really the difference between the two?

两者似乎都删除了注册到会话的所有变量.它们中的任何一个实际上破坏了会话本身吗?如果没有,您如何完成此操作(销毁会话本身).

Both seem to delete all variables registered to a session. Does any of them actually destroy the session itself? If not, how do you accomplish this (destroy the session itself).

这两个函数都没有删除客户端的会话cookie是否正确?

Is it correct that neither of the two functions deletes the session cookie at the client?

推荐答案

session_unset 只是清除 $_SESSION 变量.相当于做:

session_unset just clears the $_SESSION variable. It’s equivalent to doing:

$_SESSION = array();

所以这只会影响本地 $_SESSION 变量实例,而不影响会话存储中的会话数据.

So this does only affect the local $_SESSION variable instance but not the session data in the session storage.

与此相反,session_destroy 破坏了会话存储中存储的会话数据(例如文件系统中的会话文件).

In contrast to that, session_destroy destroys the session data that is stored in the session storage (e.g. the session file in the file system).

其他一切都保持不变.

这篇关于PHP 中的 session_unset() 和 session_destroy() 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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