Hello guys,
I'm trying to set up a cookie which would store the time when the user leaves a website, so in the next visit he can find a "There's new content" message (if any) - checked against his "last seen" stored time.
The things I'm stuck with are two : how do I send a cookie when he leaves the site ? And, then, how do I check that data when he comes back, compared to the last published content's time ?
This is the code I have by now :
<!-- 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>';
}
?>
As you see, I imagine a function called last_comment_time()
that I have still to figure out, but my main concern would still be the moment in which the cookie is sent.
Many thanks for any input / alternative solution.