PHP session_destroy ()

In my application, when a user logs out, I want to destroy all current user sessions. Do I unlock every session used in the application and then call session_destroy () or just call session_destroy ()?

Thanks!

+4
source share
3 answers

The session_destroy() function should disable all sessions you set up. So yes, you only need to call. You can test it by calling session_destroy() , then trying to display the session value, if it is an echo, then it will not work, if an error of some description appears, then the session is successfully destroyed.

-1
source

session_destroy() does not destroy all user sessions. You will need to write to permanent media (database, text file, etc.), and then call session_destroy() to kill its own session. Then, all pages check when they load. If it has a special command (for example, normal - 0 , the destroy command - 1 ), ask them to call session_destroy() .

+1
source

session_unset (): Remove all session vars. In 1rst F5, session variables are no longer displayed.

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

So 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(); 
0
source

Source: https://habr.com/ru/post/1332630/


All Articles