简体   繁体   English

如何延长cookie的过期时间(在php中设置)?

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

I have set cookie in php that is , 我已经在php中设置了cookie,

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

Now in javascript after an hour if user is active , i want to extend the time of cookie. 现在,如果用户处于活动状态,一个小时后在javascript中,我想延长cookie的时间。 And also if user is idle for more tha 15minutes i want to delete the cookie in javascript. 而且,如果用户闲置了15分钟,我想删除JavaScript中的Cookie。 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. 您是否无法通过ajax例程来检查用户是否已处于非活动状态超过15分钟,而该例程会每隔n毫秒对后端PHP例程执行一次ping操作,就对最后一次访问时间进行一次检查,如果返回,则返回用户在过去15分钟内处于活动状态。

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(). 您可以将“上次访问”时间添加到cookie值中,这样cookie的值将(可能)(由PHP初始设置)为$ 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. 无需等待一个小时来通过JavaScript更新cookie,您可以简单地通过PHP在页面加载期间更新cookie的“最后访问”时间,或使用ajax例程来实现这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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