session_start(); // To be able to use session_destroy $_SESSION = array(); // Destroys any session variables session_destroy(); // Deletes the old session file unset($_COOKIE[session_name()]); //Removes the cookie
To determine session timeouts and such, I basically set an arbitrary limit (say 30 minutes) that the user can be idle. When they first log in, I cache time() as a session variable. With each subsequent request, I compare the cached value to time(). If the difference is less than the allowed time, I cache the new value. Otherwise I log them out using the above code and redirect them somewhere.
On a sort of related note, a handy function is register_shutdown_function() which allows you to have a function execute once the script has finished. There are a lot of ways you could incorporate that into sessions, logouts, etc. But even with this, as far as I know, there is no server-side way to know for sure whether or not a browser window was closed unless the browser sends some information back to the server.
Jon
From: "Michael R. Bright" <[EMAIL PROTECTED]> Reply-To: BYU Unix Users Group <[EMAIL PROTECTED]> To: "BYU Unix Users Group" <[EMAIL PROTECTED]> Subject: [uug] PHP Question: session_destroy Date: Tue, 17 Jun 2003 10:05:28 -0600
I would like to destroy sessions on the server side when the person closes their browser. I know that their session is destroyed and the cookie is gone when they close the browser, is there any way to do this on the server side?
thanks in advance.
Michael R. Bright ____________________ BYU Unix Users Group http://uug.byu.edu/ ___________________________________________________________________ List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
____________________
BYU Unix Users Group http://uug.byu.edu/ ___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
