English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Is there a way to run PHP code when a session is destroyed, either by code itself (using session_destroy()) or by a different method, e.g. closing a web browser.

2006-07-03 00:09:00 · 2 answers · asked by digitaldanuk 2 in Computers & Internet Programming & Design

2 answers

Great question and one I looked into as well because I was familure with asp.net which does have an easy way to do what you are asking.

Unfortunatly, in PHP there is no simple way to do it, but it CAN be done.

The way to do it is to create your own session handling functions. Using the session_set_save_handler function you can set your own session callback functions. Two of these functions are the "session destroy" and the "garbage collection" callbacks.

You could add your own custom code to these 2 callbacks and whenver a session was destroyed (either by an explicit destroy, or by a timeout) your code would be called.

Check out the php website for more information:
http://www.php.net/manual/en/function.session-set-save-handler.php

Hope this helps. Good luck.

2006-07-03 03:59:45 · answer #1 · answered by JChance 1 · 5 0

PHP is server side only, sessions are destroyed client side unless you do it programatically. If you are doing it programatically, just add your code before or after the call.

2006-07-03 08:45:40 · answer #2 · answered by John J 6 · 0 0

fedest.com, questions and answers