Loading video...
Destroying Sessions
- When either the client or server determines that a session is to be ended, a session is destroyed. This
serves to:
- cut the link between any previous & any future HTTP transactions
- get rid of transient session data that is no longer needed
session_destroy()is used to destroy a session. It ensures that any session data stored on the server will be deleted.- To properly destroy a PHP session, the following steps must be taken:
- Call
session_start()to continue the session - Explicitly delete any session data stored in
$_SESSION - Explicitly delete the session cookie
- Destroy the session data on the server using
session_destroy()
- Call
- To explicitly destroy a session cookie, the functions
session_name()andsession_get_cookie_params()are useful. - After a specified amount of time, and regardless of the expiration of a session’s cookie, a session’s data file will be considered as expired, or a garbage, by PHP.
- PHP has a garbage collector process that will periodically run to remove any session data files that have been marked as garbage. There are several configuration directives in 'php.ini' related to session garbage collection.
- Additional Resources:
Destroying Sessions
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

































Start Learning Now
Our free lessons will get you started (Flash® 10 required).
Sign up for Educator.comGet immediate access to our entire library.
Features Overview