dpwtr666638 2011-07-13 15:54
浏览 356
已采纳

更新cookie时保留时间

Just a quick question. Is there any easy way how to not to change expire time in cookie while updating?

Let's say I have a cookie set to expire in 24 hours. But in the same date i update the cookie few times. But i still want the cookie expire at the same time after 24 hours.

Detailed example:

Cookie "counter" should expire on 23.07.2011 10:00. Now after one hour because of some action I update value of this cookie. if i set the time for 24 hours it would expire on 23.07.2011 11:00, but i need the expire time to stay at 23.07.2011 10:00.

Is there any easy way? Only way i can think of is to have another cookie with stored expire time, but i would swear there must be easier way, just missing something ?

Thank you

  • 写回答

2条回答 默认 最新

  • doulouxun6756 2011-07-13 16:51
    关注

    Instead of using another cookie, you could store the expiration date along with the cookie value:

    $expire = time()+$maxage;
    setcookie($name, "$expire:$value", $expire);
    

    Then you can get both data using explode:

    list($expire, $_COOKIE[$name]) = explode(':', $_COOKIE[$name], 2);
    setcookie($name, "$expire:$new_value", $expire);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器