Bharanikumar
Bharanikumar

Reputation: 25733

When user is inactive for 3 hour the session will expire. php

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 ,

<code>
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);
</code>

// 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,


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


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

i fixed the problem last night,

here is the code click here

Upvotes: 0

Views: 4018

Answers (3)

tejzpr
tejzpr

Reputation: 995

To inactivate the session exactly after three hours try calling

ini_set('session.cookie_lifetime',  10800);

from your php code.

Upvotes: 0

TuomasR
TuomasR

Reputation: 2316

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.

Upvotes: 1

Joel Etherton
Joel Etherton

Reputation: 37533

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().

Upvotes: 0

Related Questions