【问题标题】:How to set a cookie for the beginning of the next day, according to server time?如何根据服务器时间设置第二天开始的cookie?
【发布时间】:2013-09-15 09:24:06
【问题描述】:

我想设置PHP COOKIE,它应该只存储一天。 设置一天的 cookie 更容易。

如果用户在下午 6 点访问该网站,那么 cookie 应该再设置六个小时。

$tomorrow = mktime(0,0,0,$month,$date+1,$year);

其中月份、日期和年份来自 PHP 日期函数。 上面的代码会按我的预期工作吗?

或者有没有更好的方法来做到这一点?

【问题讨论】:

标签: php time session-cookies


【解决方案1】:

尝试将strtotime() 函数与tomorrow 关键字一起使用:

$tomorrow = strtotime('tomorrow');

【讨论】:

  • 如何使用php strtotime获取当前时间戳now?所以我可以测试它。
  • @PrabhaVathi strtotime('now')time() 是等价的。
猜你喜欢
  • 2018-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-09
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 2015-08-04
相关资源
最近更新 更多