Page 1 of 2

logout

Posted: Tue Jun 14, 2011 1:05 pm
by ashwood
I have my logout page which destroys the session and sets the logged_in value in my database 2 0.. (so they dont show on the users online anymore) but my problem is.. if they just close the browser without logging out.. it logs them out obviously because the browser destroys the session but the site says they are still online.. how would i do it so i can set the logged in value to 0 if they close the browser without loggin out?

Re: logout

Posted: Tue Jun 14, 2011 1:21 pm
by jacek
You can't is the short answer.

If you base the users online thing on the users that loaded a page in the last 5 minutes it will give you the desired effect.

Re: logout

Posted: Tue Jun 14, 2011 1:25 pm
by ashwood
yeah but what im saying is, it doesnt matter how long i say.. say i stayed logged in and close my browser the site would say im online all day.. doesnt do that on phpbb i get logged out and removed from the thingy even if i do just close my browser so there must be a way..

Re: logout

Posted: Tue Jun 14, 2011 1:27 pm
by jacek
phpbb bases the users online on activity over the last 5 minutes like I described.

Re: logout

Posted: Tue Jun 14, 2011 1:31 pm
by ashwood
jacek wrote:phpbb bases the users online on activity over the last 5 minutes like I described.


yeah which must be stored in the database.. so when i click off my browser somehow it removes me from the database?

Re: logout

Posted: Tue Jun 14, 2011 1:32 pm
by Temor
ashwood wrote:
jacek wrote:phpbb bases the users online on activity over the last 5 minutes like I described.


yeah which must be stored in the database.. so when i click off my browser somehow it removes me from the database?

no, when you close your browser window you stay logged in for an additional 5 minutes, and then you get removed.

Re: logout

Posted: Tue Jun 14, 2011 1:34 pm
by jacek
Temor wrote:no, when you close your browser window you stay logged in for an additional 5 minutes, and then you get removed.

Also no,

The time you were last active is update every time you load a page, nothing is removed from the database but the time stops being updated if you close the browser.

Re: logout

Posted: Tue Jun 14, 2011 1:34 pm
by ashwood
how does it know ive closed my browser though? really dont get this...

Re: logout

Posted: Tue Jun 14, 2011 1:35 pm
by ashwood
jacek wrote:
Temor wrote:no, when you close your browser window you stay logged in for an additional 5 minutes, and then you get removed.

Also no,

The time you were last active is update every time you load a page, nothing is removed from the database but the time stops being updated if you close the browser.



ahhhh... how do i do this sort of thing then?

Re: logout

Posted: Tue Jun 14, 2011 1:35 pm
by jacek
ashwood wrote:ahhhh... how do i do this sort of thing then?

How I just described :?

Re: logout

Posted: Tue Jun 14, 2011 1:37 pm
by Temor
jacek wrote:
Temor wrote:no, when you close your browser window you stay logged in for an additional 5 minutes, and then you get removed.

Also no,

The time you were last active is update every time you load a page, nothing is removed from the database but the time stops being updated if you close the browser.

That's kinda what I meant, I just naturally assumed you refreshed/loaded the page right before closing the window ( that's what I do... )

Re: logout

Posted: Tue Jun 14, 2011 2:05 pm
by ashwood
is it php? ajax? jquery?

Re: logout

Posted: Tue Jun 14, 2011 4:02 pm
by jacek
ashwood wrote:is it php? ajax? jquery?

Don't ask silly questions ! On;y one of those can work with mysql.

Re: logout

Posted: Wed Jun 15, 2011 9:45 am
by ashwood
lol sorry, so where do i go in php then? because im thinking i must need to set a timer? OR do i send the time to the database they logged in... then everytime they click a page that time updates BUT in the background have a jquery timer counting in a php file that looks in the database every 5 minutes and if the time is 5minutes less than the current time then remove that person from online users?

edit: sack the jquery timer is there a php function for current time? time()? ive never had to use anything like time or date yet..

Re: logout

Posted: Wed Jun 15, 2011 10:48 am
by JelvinJS7
Hypothetically speaking, couldnt you use the window object in JavaScript, and use that to see if the browser has closed, and if it has; run the php/mysql code?

Re: logout

Posted: Wed Jun 15, 2011 11:59 am
by jacek
ashwood wrote:in the background have a jquery timer counting in a php file

*facepalm* ... no.

JelvinJS7 wrote:couldnt you use the window object in JavaScript, and use that to see if the browser has closed

Yes but the problem there is that the browser runs the javascript, so if its closed ...

You do not need to do anything when they close the window, or log out. You need to update the time they last loaded a page when they load a page.

Re: logout

Posted: Wed Jun 15, 2011 2:10 pm
by ashwood
jacek wrote:You do not need to do anything when they close the window, or log out. You need to update the time they last loaded a page when they load a page.


so do i do what i said? when they log in.. send the time to the database.. then everytime they load a page send the time to the database.. over the top of the old one obviously.. then have a php file that checks every 5 minutes the time on all users and if the time is 5minutes less than the time it is now then remove that user from online users?

i have a idea of how to do it in my head.. can you confirm that, that is how i would do it?

Re: logout

Posted: Wed Jun 15, 2011 2:30 pm
by jacek
ashwood wrote:so do i do what i said? when they log in.. send the time to the database.. then everytime they load a page send the time to the database.. over the top of the old one obviously..

Yes.

ashwood wrote:then have a php file that checks every 5 minutes the time on all users and if the time is 5minutes less than the time it is now then remove that user from online users?

You could, but you could also just leave the info in the table and use something like

[syntax=sql]SELECT `username` FROM `users_online` WHERE `last_online` > (UNIX_TIMESTAMP() - 300)[/syntax]
to get the users online in the last 5 minutes.

Re: logout

Posted: Wed Jun 15, 2011 2:33 pm
by bowersbros
you can do it with a very small java applet.. making it fairly useless, sicne people need to accept java applets to run.

But;

you can use the stop() method in an applet, and get it to fire a script that logs them out of the database too.

The way this works is whenever the browser is closed (by the cross, Alt F4 or whatever way they do it) it fires that method before it closes.

http://www.cafeaulait.org/course/week5/28.html

Re: logout

Posted: Wed Jun 15, 2011 2:37 pm
by jacek
bowersbros wrote:making it fairly useless, sicne people need to accept java applets to run.

That's quite an important point. Most people would reject it if they were not expecting to be asked to run an applet ;). Interesting proof of concept though.

Re: logout

Posted: Wed Jun 15, 2011 2:40 pm
by bowersbros
jacek wrote:
bowersbros wrote:making it fairly useless, sicne people need to accept java applets to run.

That's quite an important point. Most people would reject it if they were not expecting to be asked to run an applet ;). Interesting proof of concept though.


yeah, pity you cant run something similar with just javascript or something, to get it to work without being accepted. :(