开发者

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("sessio开发者_运维百科n.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


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.


To inactivate the session exactly after three hours try calling

ini_set('session.cookie_lifetime',  10800);

from your php code.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜