Reputation: 113
How can I set a cookie and retrieve the cookie value in Drupal 8?
In plain PHP, I could use setcookie('country', $country, time() + (86400 * 30), "/");
, but I think there is a better way, for Drupal 8.
Upvotes: 2
Views: 8354
Reputation: 12775
Take a look at user_cookie_save()
which accepts an array of values.
user_cookie_save(['your_cookie' => "your_value"])
Creates a Drupal.visitor.your_cookie
cookie:
Upvotes: 4