proper way to logout from a session in PHP

后端 未结 4 1976
误落风尘
误落风尘 2020-11-28 09:00

I have read many php tutorials for logout scripts, i am wondering what could be the proper way to logout from a session!

Script 1



        
4条回答
  •  时光取名叫无心
    2020-11-28 09:47

    Personally, I do the following:

    session_start();
    setcookie(session_name(), '', 100);
    session_unset();
    session_destroy();
    $_SESSION = array();
    

    That way, it kills the cookie, destroys all data stored internally, and destroys the current instance of the session information (which is ignored by session_destroy).

提交回复
热议问题