Page 1 of 1
Do something after the user closes browser?!
Posted: Fri Dec 27, 2002 11:39 pm
by BigRed
I got another question. Can I make PHP do something after the user closes him/her browser? My site runs on sessions and I want php to delete a row from a database after a user "logs off" from my site.
Any suggestions?
Posted: Sat Dec 28, 2002 5:11 am
by Elmseeker
I think you just have to wait for the session to time out...not positive though...but as far as I know, since PHP is server side it doesn't really have any way of knowing that the client has closed their browser and therefor can't do anything about it.
Posted: Sat Dec 28, 2002 12:48 pm
by BigRed
How can I set the timeout for the session. I didn't set a timeout for the sessions I use

Posted: Sat Dec 28, 2002 12:56 pm
by oldtimer
php.ini file will do that. You can set it to stop using the session to any interval you like. It will not purge it from your database however.
One thing you can do is have an insert at the top of each page to purge any row thats session time is greater than the specified time. I use this for a usersonline script. When the page is loaded it purges any entry that is more than 6 minutes old.
Posted: Sat Dec 28, 2002 12:58 pm
by zacky
set a timestamp when you start's a session and update the timestamp when the user do something.. and delete the session if timestamp is more than 30min old..
Posted: Sat Dec 28, 2002 1:32 pm
by BigRed
Got it. Thanks. It works.
Posted: Sun Dec 29, 2002 8:11 am
by goranrakic
You can add onClose javascript that will open small window with php file in it. You can do anything you want and than send small javascript that will close the window. You need to do that fast, without anoying visitor. It will not work with some popup stopers or javascript disabled browsers.