ankur0101 Posted January 27, 2013 Share Posted January 27, 2013 Hi friends, My Post title says it all. How to extend cookie expiry date from last activity which user has done ? Lets take an example, by default, cookie is set for 30minutes after user login. userA do login at 1PM, hence given cookie will expire at 1.30PM. Problem with this scenario is that if userA is doing something very important activity in app, then when he click on submit form on any internal link, he will get redirected to login. Hence he loses his work which he as done. What I want to have is when userA log in at 1PM (First activity), then at first, cookie will expire at 1.30PM. After that userA become idle, that means he does not click anywhere, he just leave his computer and come back again after 15 minutes i.e. at 1.15PM and starts using php portal, then cookie expiry should become 1.45PM How to do that ? I found script PHPmyadmin has done same thing. It leads to expiration of cookie when user become inactive for more that 1440 seconds. How to do that ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/273687-how-to-extend-cookie-expiry-from-users-last-activity/ Share on other sites More sharing options...
ignace Posted January 27, 2013 Share Posted January 27, 2013 (edited) Is this a session cookie? If so, you can set the expire date with session_set_cookie_params. If not, then you can simply extend the lifetime of the cookie by calling setcookie with the exact same name and setting a new expire date. You can also use setcookie to extend the session cookie's lifetime. setcookie( session_id(), serialize($_SESSION), time() + 1440/*ini_get('session.cookie_lifetime'),*/, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly') ); Edited January 27, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/273687-how-to-extend-cookie-expiry-from-users-last-activity/#findComment-1408498 Share on other sites More sharing options...
Christian F. Posted January 27, 2013 Share Posted January 27, 2013 Another option, if there are only a few tasks that can take a lot of time, is to have a AJAX process intermittently send a request to the server (when doing said tasks). A HEAD(er) request will do, as that'll get a new cookie from the server set to expire in another 30 minutes. Quote Link to comment https://forums.phpfreaks.com/topic/273687-how-to-extend-cookie-expiry-from-users-last-activity/#findComment-1408509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.