I need to save a cookie for anonymous users in Drupal 8 when users visit the site for the first time, which will be used to display a message.
I can successfully save one using
setcookie("FirstTimer", 1, strtotime('+1 year')); but I am sure Drupal 8 should have some alternatives.
I can also use the following code.
$user_is_first_timer = !isset($_COOKIE["Drupal_visitor_FirstTimer"]);
When I open it in Google Chrome, this works, but when I open it in incognito or in Firefox, there is no message. Somehow cached pages are being served.
The code is used in an implementation of