Do something after the user closes browser?!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
BigRed
Forum Newbie
Posts: 6
Joined: Thu Dec 26, 2002 11:47 am

Do something after the user closes browser?!

Post 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?
User avatar
Elmseeker
Forum Contributor
Posts: 132
Joined: Sun Dec 22, 2002 5:48 am
Location: Worcester, MA

Post 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.
User avatar
BigRed
Forum Newbie
Posts: 6
Joined: Thu Dec 26, 2002 11:47 am

Post by BigRed »

How can I set the timeout for the session. I didn't set a timeout for the sessions I use 8O
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post 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.
zacky
Forum Newbie
Posts: 19
Joined: Fri Nov 29, 2002 6:08 am

Post 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..
User avatar
BigRed
Forum Newbie
Posts: 6
Joined: Thu Dec 26, 2002 11:47 am

Post by BigRed »

Got it. Thanks. It works.
goranrakic
Forum Newbie
Posts: 3
Joined: Thu Dec 26, 2002 8:48 am
Location: Serbia (Yugoslavia)
Contact:

Post 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.
Post Reply