Page 1 of 1

Please Help

Posted: Mon Mar 27, 2006 7:10 am
by Mothanna1982
Hello guys


i have a web page that contains a login form,now when the user logged in i set some flag to 1 which use to detect online users,and when the user logg out of course set the flag to 0
but the problem is when the user close his browser without click log off the flag save its value (1)
and the user seem as if online permanently

please how i can solve this problem :?:

logout problem

Posted: Mon Mar 27, 2006 8:29 am
by jito
hi,
Although i am not a web programming guru, just trying to solve ur problem with my little knowledge.try this code...
<BODY onbeforeunload="call_a_function()">
we need an onbeforeunload event that fires prior to a page being unloaded.
set ur flag variable to 0 using that function.

If u need the code i'm there. But i think u should better use session concept rather using a flag variable.

Posted: Mon Mar 27, 2006 9:55 am
by Nathaniel
Put a new field in your users table (the one that has the flag which tells if the user is online) named session_time or similar. Every time the user goes to a page, update that session_time field to the current time. For an example on how to grab all of the users who has been online in the last five minutes:

Code: Select all

$online_time = time() - 300 // 300 = 60 seconds x 5
$sql = "SELECT * FROM users WHERE session_time > $online_time";
Optionally, you could add " AND flag = '1'" to that sql query, and it wouldn't select anyone who had hit the logout button before closing their browser.

- Nathaniel

Posted: Mon Mar 27, 2006 10:25 am
by patrikG
check out the garbage collection of session_set_save_handler (i.e. session times out and you define what's going to happen, i.e. set user_flag to 0 or whatever else you need).

session_set_save_handler()

Posted: Mon Mar 27, 2006 12:42 pm
by Mothanna1982
Yes thank u Mr patrikG

i am junior web programmer

how i can use session_set_save_handler() to execute some code when gc is invoked

Posted: Mon Mar 27, 2006 1:00 pm
by feyd
set the garbage collection function reference.

details

Posted: Mon Mar 27, 2006 4:19 pm
by Mothanna1982
please some details
please :oops:

Posted: Mon Mar 27, 2006 4:40 pm
by feyd
Did you read the manual page that patrikG linked to? Did you notice the code example on the page? Did you try it? What's the problem?

gc does not execute

Posted: Tue Mar 28, 2006 6:18 am
by Mothanna1982
Mr feyd
the problem is that gc functions does not execute
i set the maxlifetime to 5 seconds in php.ini
but no execution
When this function execute exactly

Posted: Tue Mar 28, 2006 9:33 am
by feyd
The function will execute based on your php's settings. session.gc_probability and session.gc_divisor set how often php will call the garbage collector.

For example, the defaults 1 and 100, respectively, means PHP will call the garbage collector once per 100 sessions.

only gc

Posted: Tue Mar 28, 2006 9:48 am
by Mothanna1982
yes i find that the gc executed when openning new session
with the probality of 1/100 by default

can i

Posted: Tue Mar 28, 2006 1:20 pm
by Mothanna1982
Hello all again
thanks 4 all replys
but i wanna ask can i tell session_set_save_handler() to execute only gc function