【发布时间】:2010-02-22 01:52:05
【问题描述】:
我正在尝试设置一个 cookie 来存储用户离开网站的时间,因此在下次访问时,他可以找到“有新内容”消息(如果有的话) - 检查他的“最后一次看到” " 存储时间。
我遇到的问题有两个:当他离开网站时,我如何发送 cookie?那么,与上次发布内容的时间相比,我如何在他回来时检查该数据?
这是我现在拥有的代码:
<!-- I send the cookie -->
<?php
// How long should something be considered new for? (In seconds.)
// seconds * minutes * hours * days
// Default is 72 hours (3 days).
$stillnew = 60*60*24*3;
setcookie('CookiePublishing', time()-$stillnew, time()+60*60*24*30, '/');
?>
<!--I check the cookie and print -->
<?php
$entrydate = last_comment_time();
if ($_COOKIE['CookiePublishing'] < $entrydate) {
echo '<p>New Comment!</p>';
}
?>
如您所见,我想象一个名为 last_comment_time() 的函数,我仍然需要弄清楚,但我主要关心的仍然是发送 cookie 的时间。
非常感谢您提供任何输入/替代解决方案。
【问题讨论】:
标签: php session comments cookies