PHP Proper Logout Code
To provide a logout function, we have to destroy the session and expire the cookie (if cookies are being used to pass along the session identifier). Based on the PHP manual, you have something like this…
Yes, the set_cookie function is a bit complex. The reason you set $_SESSION to an empty array even though you are destroying the session is that session_destroy() is done upon garbage collection and not done immediately. Setting to empty array, clears the session immediately.