PHP Cookies and message for new articles

I’d like to display a little “new” text message for newer articles in the different categories on a website since the user last visited.
I think cookies is the way to go.

I don’t know if passing cookies in PHP is a great solution here, but I guess it is (since it won’t be so simple in js?).
The idea would be to check the number of projects in categories and compare them to the last visit. If n of projects in category X > n of projects in category X at date -last visit- then...

Is there a good way to go here, or something that could be suggested ?
Thanks a lot!

You only need to store the last visit date, not number of articles etc.

Hey, thanks for your reply!
I don’t see how I can do what I need without storing the number of articles?

My thought was that those articles had a date stored, but if that doesn’t make sense, then I guess you need to store the number of articles as well.

Oh, is there a method to get the page creation date automatically?
beside that post $page->created()

No, there is no native $page->created() unless you store a date at creation as in the example. As I wrote above, I was assuming that an article has at least a publication date.

It does now! :slight_smile:

here is what I made so far: this code stores your latest visit in a cookie and then get the projects newly created.

setcookie('lastVisit', date("Y-m-d G:i:s"));
if (isset($_COOKIE['lastVisit'])) {
    $lastVisit = $_COOKIE['lastVisit'];
    $projectList = $site->find("projets")->children();
    echo "Your last last visit was - " . $lastVisit . "......";
    echo "these projects were created after your last visit: ";

    foreach ($projectList as $project) {
        $projectCreated = $project->created();
        $lastVisitFormated = $lastVisit;

        if ($projectCreated > $lastVisitFormated) {
            $projectTitle = $project->title();
            $projectCat = $project->category();
            echo  $projectTitle . $projectCreated . $projectCat;
} else
    echo "You've got some stale cookies!";

I’d filter the projects by created date instead of using an if statement in the loop:

$newProjects = page('projets')->children()->filterby('created', '>' $lastVisit);