PHP loggout

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
Spears
Forum Newbie
Posts: 6
Joined: Mon Mar 23, 2009 10:06 am

PHP loggout

Post by Spears »

In the game I'm writing, I have a logout.php file that logs the user out. My problem is if someone closes out of the game without clicking the logout file, it tends to mess things up. Is there a good way to make it where clicking the X logs someone out?
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: PHP loggout

Post by mattpointblank »

You can't track whether the user closes the window or not using PHP, but you could use session variables to track user activity - if they don't do anything for (say) 10 minutes, assume they closed the window and run the logout code automatically for them.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: PHP loggout

Post by Mark Baker »

or you can always look at using onBeforeUnload/onUnload in javascript to send a logout request to the server, but these can also be triggered when moving from one page to another, or when hitting refresh in the browser
Post Reply