working with sessions

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
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

working with sessions

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

No standards. You will find many available registering/authenticating/logging in/logging out scripts available though.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: working with sessions

Post 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.
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Post 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...
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

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