Documentation

Cookie

Cookie class for handling cookie files.

Similar methods in the old core:
CMain::set_cookie - for creating,
CMain::get_cookie - for getting.

Cookie can be specified in the core D7 via the class Bitrix\Main\HttpResponse, they can be retrieved via the class link=11513894]Bitrix\Main\HttpRequest[/link].

Example

use Bitrix\Main\Application;
use Bitrix\Main\Web\Cookie;
$cookie = new Cookie("TEST", 42);
$cookie->setDomain("example.com");
Application::getInstance()->getContext()->getResponse()->addCookie($cookie);
// Cookie will be available only at the next hit!
echo Application::getInstance()->getContext()->getRequest()->getCookie("TEST");
© «Bitrix24», 2001-2024
Up