Destroying Sessions and Unsetting Elements

You can use session_destroy() to end a session, erasing all session variables. session_destroy() requires no arguments. You should have an established session for this function to work as expected. The following code fragment resumes a session and abruptly destroys it:

session_start();
session_destroy();

When you move on to other pages that work with a session, the session you have destroyed will not be available to them, forcing them to initiate new sessions of their own. Any variables that have been registered will have been lost.

However, session_destroy() does not instantly destroy elements of the $_SESSION array. These remain accessible to the script in which session_destroy() is called (until ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.