开发者

PHP session_destroy()

开发者 https://www.devze.com 2023-01-31 10:51 出处:网络
In my application, when the user logs out, I want to destroy all the current user\'s sessions. Do I u开发者_如何学Cnset each session used in the application and then call session_destroy() or just cal

In my application, when the user logs out, I want to destroy all the current user's sessions. Do I u开发者_如何学Cnset each session used in the application and then call session_destroy() or just call session_destroy()?

Thank you!


session_destroy() does not destroy all user's sessions. 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. 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().


session_unset(): Remove all session vars. In the 1rst F5 no longer display the session variables.

session_destroy(): Delete the current session. In the 2dn F5 no longer display the session variables.

Therefore your logout.php script could be:

<?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. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号