Magento – How to Use Session or Cookie in Magento 2.0

cookiecustomer-sessionmagento2

I am going to add Age verification block on Home page. for that i want to set session or cookie variable. so that i can check it through out all pages of store weather age verification session or cookie set or not.

Best Answer

You can use the below classess to set cookie and session in your block by passing into dependency.

Magento\Framework\Session\SessionManagerInterface;

Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;

Magento\Framework\Stdlib\Cookie\PublicCookieMetadata;

Magento\Framework\Stdlib\CookieManagerInterface;

For reference link

Hope it helps.

Related Topic