简体   繁体   中英

How to extend the expiry time of cookie , that set in php?

I have set cookie in php that is ,

setcookie("username",$username,time()+3600);

Now in javascript after an hour if user is active , i want to extend the time of cookie. And also if user is idle for more tha 15minutes i want to delete the cookie in javascript. Is it possible ? Any help?

Couldn't you acheive the check to see if the user has been inactive for more than 15 minutes with an ajax routine that would ping a back end PHP routine, every n milliseconds, that runs a check against the last access time, returning if the user has been active in the last 15 minutes.

You could add the 'last access' time to the cookies value, so the value of the cookie would (could) be (as set by PHP initialy) $username.';'.time(). You could then run date routines against it.

Rather than wait for an hour to update the cookie via JavaScript, you could simply update the cookies 'last access' time across page loads via PHP, or use the ajax routine to acheive this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM