简体   繁体   English

PHP session_destroy()

[英]PHP session_destroy()

In my application, when the user logs out, I want to destroy all the current user's sessions. 在我的应用程序中,当用户注销时,我想销毁所有当前用户的会话。 Do I unset each session used in the application and then call session_destroy() or just call session_destroy()? 我是否取消设置应用程序中使用的每个会话,然后调用session_destroy()或只调用session_destroy()?

Thank you! 谢谢!

session_destroy() does not destroy all user's sessions. session_destroy()不会破坏所有用户的会话。 You would need to write to a persistent storage media (database, text file, etc.) and then call session_destroy() to kill it's own session. 您需要写入持久性存储介质(数据库,文本文件等),然后调用session_destroy()来杀死它自己的会话。 Then, have all pages check it when they load. 然后,让所有页面在加载时检查它。 If it has some special command in it (for example, normal is 0 , destroy command is 1 ), have them call session_destroy() . 如果它中有一些特殊命令(例如,normal为0 ,destroy命令为1 ),请让它们调用session_destroy()

session_unset(): Remove all session vars. session_unset():删除所有会话变量。 In the 1rst F5 no longer display the session variables. 在第一个F5中不再显示会话变量。

session_destroy(): Delete the current session. session_destroy():删除当前会话。 In the 2dn F5 no longer display the session variables. 2dn F5中不再显示会话变量。

Therefore your logout.php script could be: 因此,您的logout.php脚本可能是:

<?php
session_start();

...

// remove all session variables
session_unset(); 

// destroy the session 
session_destroy();

// Redirect to home
header("Location: home.php");
exit();

The session_destroy() function should unset all sessions that you have set. session_destroy()函数应该取消设置您设置的所有会话。 So yes, you should only have to call that. 所以是的,你应该只需要打电话。 You can test it by calling session_destroy() then trying to echo a session value, if it echoes then it's not worked, if an error of some description appears, then the session has successfully been destroyed. 您可以通过调用session_destroy()然后尝试回显会话值来测试它,如果它回显然后它不起作用,如果出现某些描述的错误,则会话已成功销毁。

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

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