Page 1 of 1

working with sessions

Posted: Sun Sep 23, 2007 5:44 am
by kkonline
1> I want to have a time limit for the sessions ... means if the user is online then his session should expire if he's logged in and INACTIVE for 5 mins say.

Is it possible if the user is active or inactive after he logs.

2> I want to count the total time the user is actively online till date. (counts the number of seconds he's online ever since he registered)

How to do the above tasks...

Is there any standard code or class which can be used for authenticating and registering users because it's very common for any site

Posted: Sun Sep 23, 2007 5:50 am
by s.dot
1) Two options. Make the session max life time 5 minutes. Through the php.ini file or through the use of ini_set(). You'll be looking for session.gc_max_lifetime in both cases.

The second option would be storing the timestamp of each page load the user does. On the subsequent pageloads, check if that stored timestamp is less than 5 minutes ago.. if so, log them out.

2) That's a pretty difficult situation without a logout function (even so, users may close the browser). Not entirely sure how to tell you to go about that one.

Posted: Sun Sep 23, 2007 5:59 am
by kkonline
scottayy wrote:1) Two options. Make the session max life time 5 minutes. Through the php.ini file or through the use of ini_set(). You'll be looking for session.gc_max_lifetime in both cases.

The second option would be storing the timestamp of each page load the user does. On the subsequent pageloads, check if that stored timestamp is less than 5 minutes ago.. if so, log them out.

2) That's a pretty difficult situation without a logout function (even so, users may close the browser). Not entirely sure how to tell you to go about that one.
Is there any standard code or class which can be used for authenticating and registering users because it's very common for any site?

Posted: Sun Sep 23, 2007 6:09 am
by s.dot
No standards. You will find many available registering/authenticating/logging in/logging out scripts available though.

Re: working with sessions

Posted: Sun Sep 23, 2007 6:47 am
by superdezign
kkonline wrote:1> I want to have a time limit for the sessions ... means if the user is online then his session should expire if he's logged in and INACTIVE for 5 mins say.
Using the max time limit isn't going to exactly do that, as the GC for sessions isn't instant. If you manage your sessions through the database though, you could force the expiration.
kkonline wrote:2> I want to count the total time the user is actively online till date. (counts the number of seconds he's online ever since he registered)
Seems pretty pointless to me. There aren't many accurate ways of doing this, but you could constantly "ping" the user using AJAX to check if they are online and add that particular interval to their counter.

Posted: Sun Sep 23, 2007 6:47 am
by kkonline
scottayy wrote:No standards. You will find many available registering/authenticating/logging in/logging out scripts available though.
Ok, is there any better one which you'll recommend ? Or it's better to write my own as i am doing...

Posted: Sun Sep 23, 2007 9:00 am
by superdezign
kkonline wrote:
scottayy wrote:No standards. You will find many available registering/authenticating/logging in/logging out scripts available though.
Ok, is there any better one which you'll recommend ? Or it's better to write my own as i am doing...
It's hard to have a standard method of user authentication, especially since most applications have their own built in user authentication. The methods you use to save your user information, or retrieve user data, or handle user sessions, or allow users to communicate make a lot of it very custom. Luckily, it's really not too hard to start your own, and you're better off with a more intimate understanding of your user system.