logout

Ask about a PHP problem here.
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

logout

Post 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?
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: logout

Post 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.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: logout

Post 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..
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: logout

Post by jacek »

phpbb bases the users online on activity over the last 5 minutes like I described.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: logout

Post 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?
I would put a signature.. BUT, i don't have the time.
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: logout

Post 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.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: logout

Post 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.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: logout

Post by ashwood »

how does it know ive closed my browser though? really dont get this...
I would put a signature.. BUT, i don't have the time.
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: logout

Post 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?
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: logout

Post by jacek »

ashwood wrote:ahhhh... how do i do this sort of thing then?

How I just described :?
Image
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: logout

Post 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... )
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: logout

Post by ashwood »

is it php? ajax? jquery?
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: logout

Post by jacek »

ashwood wrote:is it php? ajax? jquery?

Don't ask silly questions ! On;y one of those can work with mysql.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: logout

Post 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..
I would put a signature.. BUT, i don't have the time.
JelvinJS7
Posts: 341
Joined: Thu May 12, 2011 8:40 pm

Re: logout

Post 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?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: logout

Post 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.
Image
ashwood
Posts: 144
Joined: Thu May 12, 2011 7:17 am

Re: logout

Post 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?
I would put a signature.. BUT, i don't have the time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: logout

Post 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.
Image
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: logout

Post 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
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: logout

Post 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.
Image
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: logout

Post 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. :(
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Post Reply