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 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退