Views: 3287
Last Modified: 05.05.2022

You can handle the variable $_SESSION directly, however such approach is not advised. All data changes in the global variable will be saved, but we strongly recommend to use the new Bitrix24 API instead of this variable.

Instead of directly using the variable, it's better to use the object, returned by the method \Bitrix\Main\Application::getSession():

$session = \Bitrix\Main\Application::getInstance()->getSession();
if (!$session->has('foo'))
{
    $session->set('foo', 'bar');            
}

echo $session['foo']; //bar

This object is implemented by the interface \ArrayAccess, as well as by \Bitrix\Main\Session\SessionInterface.



Courses developed by Bitrix24