Please Help

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
Mothanna1982
Forum Newbie
Posts: 6
Joined: Mon Mar 27, 2006 6:51 am

Please Help

Post 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 :?:
jito
Forum Commoner
Posts: 85
Joined: Sat Mar 25, 2006 4:32 am
Location: india

logout problem

Post 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.
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post 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
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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).
Mothanna1982
Forum Newbie
Posts: 6
Joined: Mon Mar 27, 2006 6:51 am

session_set_save_handler()

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

set the garbage collection function reference.
Mothanna1982
Forum Newbie
Posts: 6
Joined: Mon Mar 27, 2006 6:51 am

details

Post by Mothanna1982 »

please some details
please :oops:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
Mothanna1982
Forum Newbie
Posts: 6
Joined: Mon Mar 27, 2006 6:51 am

gc does not execute

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Mothanna1982
Forum Newbie
Posts: 6
Joined: Mon Mar 27, 2006 6:51 am

only gc

Post by Mothanna1982 »

yes i find that the gc executed when openning new session
with the probality of 1/100 by default
Mothanna1982
Forum Newbie
Posts: 6
Joined: Mon Mar 27, 2006 6:51 am

can i

Post 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
Post Reply