(PHP) How to destroy the session cookie correctly?

前端 未结 3 828
我在风中等你
我在风中等你 2020-11-28 15:02

I\'m trying to correctly log out of an admin user. Here is my function:

function logout()
{
    $_SESSION = array(); //destroy all of the session variables
          


        
3条回答
  •  甜味超标
    2020-11-28 15:30

    If you really want to cover all bases try doing:

    setcookie (session_id(), "", time() - 3600);
    session_destroy();
    session_write_close();
    

    That should prevent further access to the session data for the rest of PHP execution. The browser may still show the cookie being set however the $_SESSION super will be blank

提交回复
热议问题