Skip to main content

Drupal 8 cookies can be set using ResponseHeaderBag from the Symfony\Component\HttpFoundation\Response object.

Set new cookie value

use Symfony\Component\HttpFoundation\Cookie;

$cookie = new use Cookie('cookie_name', TRUE); $response->headers->setCookie($cookie); return $response; 

Get cookies value

$request->cookies->get('cookie_name'); 
bpile
  • 318
  • 3
  • 5