Jump to content

[SOLVED] Log Out


rascle

Recommended Posts

Hi

I have a basic User login on my website using sessions and at the moment i have a Log out Button which breaks the session and it also sends a message to my MySQL DB saying you have been logged out (since other members can see if a member is online or not) but the problem that i have is that some people dont log out they just close the browser so they are still online even though they arent if you get what i mean! and i was wondering if anyone could give me a code or tutorial to make it so when the webpage is closed send the message to the MySQL db saying you have left the building? I was thinking maybe writing something like if the session is broken (when they close the page down) send a message to the DB, does anyone know if this would work? if not could i try and do something by mixing PHP and Javascript (i know one is a server side and the other isnt) but is it possible maybe by using Javascripts onpageexit (or whatever)???

Thanks

Link to comment
https://forums.phpfreaks.com/topic/141140-solved-log-out/
Share on other sites

Hi

I have a basic User login on my website using sessions and at the moment i have a Log out Button which breaks the session and it also sends a message to my MySQL DB saying you have been logged out (since other members can see if a member is online or not) but the problem that i have is that some people dont log out they just close the browser so they are still online even though they arent if you get what i mean! and i was wondering if anyone could give me a code or tutorial to make it so when the webpage is closed send the message to the MySQL db saying you have left the building? I was thinking maybe writing something like if the session is broken (when they close the page down) send a message to the DB, does anyone know if this would work? if not could i try and do something by mixing PHP and Javascript (i know one is a server side and the other isnt) but is it possible maybe by using Javascripts onpageexit (or whatever)???

Thanks

 

You have to set a timeout. If the user has not been active in x minutes set them as being logged out. That is the only "accurate" way to do this. If they browse another page, reset their DB status to online.

 

EDIT:

http://www.google.com/search?hl=en&q=users+online+script+php&btnG=Google+Search&aq=f&oq=

Some scripts there should have examples of how to do this if you need one.

Link to comment
https://forums.phpfreaks.com/topic/141140-solved-log-out/#findComment-738739
Share on other sites

Detecting the closing of the browser tab/window could only be done with JavaScript. Don't know if it will work for both tabs and the window or even how cross-browser compatible it is. So, it could be possible to fire off an AJAX request to update the database.

 

But, a better solution, which I assume most every site uses, is to simply set a timestamp of the last user activity. Then when checking for "online" users query for users who's timestamp is within the last x minutes.

Link to comment
https://forums.phpfreaks.com/topic/141140-solved-log-out/#findComment-738744
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.