how to logout from a php session - session_destroy doesn't seem to be enough

后端 未结 6 737
囚心锁ツ
囚心锁ツ 2021-01-15 19:01

I\'m trying to learn PHP and using sessions. I seen examples about using session_destroy on logout, but I see this in the php documentation:

In order

6条回答
  •  无人及你
    2021-01-15 19:35

    I've never actually deleted the session ID from the session. I usually just unset the necessary variables from the session (so if, for instance, you set a logged in user as $_SESSION['user'] = $userModel; then I just unset($_SESSION['user']);). To remove the cookie from the user's browser (like the documentation says) do this:

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

    Read Example #1 from the session_destroy() documentation for more info.

提交回复
热议问题