tags:

views:

269

answers:

6

When user is inactive for 3 hour ,How to set session expire.

Surly this is duplicate question ,

But other threads are not worked for me,

what i have tried upto now is ,

define("APP_SESSION_TIMEOUT","10"); session_cache_expire(APP_SESSION_TIMEOUT); session_set_cookie_params(APP_SESSION_TIMEOUT*60); ini_set("session.gc_maxlifetime", APP_SESSION_TIMEOUT * 60);

// Not This code is in my config.php

am not find, success on my above code .. any tips,

i maked any mistake in my code,

A: 

If you have access to the php.ini file, you can set it in there. If you don't (which I suspect is the case), you'll need to create a session variable that indicates the start of the session, and continually update that variable with the current timestamp. Then with each access, compare the session variable with the current timestamp and if the difference is greater than 3 hours, call session_destroy().

Joel Etherton
This changes affect only when the system is idle ?
Bharanikumar
You would have to use timestamps to compare. If you update the timestamp each time the user makes an action, then a difference in session timestamp and post timestamp would be a good measure inactivity. Also, it could be embedded into AJAX calls through context so you could define "idle" as something other than the time between page posts. Keystrokes could even be used if you wanted to go that granular (I wouldn't).
Joel Etherton
+1  A: 

This code:

session_set_cookie_params(APP_SESSION_TIMEOUT*60); 

is probably not what you want. As APP_SESSION_TIMEOUT is defined also as a string, you're multiplying "10" * 60. This will also amount only to 600 seconds (even if PHP does the calculation correctly).

Do this:

session_set_cookie_params(3600 * 3); // 3600 seconds (one hour) * 3
session_start();

This should set the max. time for the session to three hours.

TuomasR
A: 

Usefull one , let i will try this..soonly give u reply...

Bharanikumar
A: 

To inactivate the session exactly after three hours try calling

ini_set('session.cookie_lifetime',  10800);

from your php code.

thinktejas
hi is it possible to check my reply..
Bharanikumar
A: 

Hi am not sure, my code is correct,

but still i have a problem ,

am getting confussion,

click here

my requirement is when system is active for 3 hours , then login automatically goes to logout,(ie is session expire , when system is in active for 3hr)

But my code , not goign to expire mode,

i have tried somthing like

ini_set('session.cookie_lifetime',  10800);
ini_set('session.gc_maxlifetime',  10800);

no luck still.....

Bharanikumar
Have you tried checking the cookie parameters that are set by PHP? For example in Firefox, goto Preferences -> Privacy -> click on "remove individual cookies" and find your cookie and see what it says on "Expire".To clarify, do you really want to logout users after 3 hours of activity time or 3 hours of INactivity time?
TuomasR
A: 

Am not sure, where is the exact mistake, but finaly,

i fixed the problem last night,

here is the code click here

Bharanikumar