• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/user.php
  • Класс: CAllUser
  • Вызов: CAllUser::Logout
public function Logout()
{
	/** @global CMain $APPLICATION */
	global $APPLICATION;

	$USER_ID = $this->GetID();

	$arParams = [
		"USER_ID" => &$USER_ID,
	];

	$APPLICATION->ResetException();
	$bOk = true;
	foreach (GetModuleEvents('main', 'OnBeforeUserLogout', true) as $arEvent)
	{
		if (ExecuteModuleEventEx($arEvent, [&$arParams]) === false)
		{
			if (!($APPLICATION->GetException()))
			{
				$APPLICATION->ThrowException("Unknown logout error");
			}

			$bOk = false;
			break;
		}
	}

	if ($bOk)
	{
		foreach (GetModuleEvents('main', 'OnUserLogout', true) as $arEvent)
		{
			ExecuteModuleEventEx($arEvent, [$USER_ID]);
		}

		if (($storedAuthId = $this->getContext()->getStoredAuthId()) > 0)
		{
			UserStoredAuthTable::delete($storedAuthId);
		}

		$this->justAuthorized = false;
		$this->admin = null;
		$this->context = null;

		static::$kernelSession["SESS_AUTH"] = [];
		unset(static::$kernelSession["SESS_AUTH"]);
		unset(static::$kernelSession["SESS_OPERATIONS"]);
		unset(static::$kernelSession['fixed_session_id']);

		$application = MainApplication::getInstance();

		//change session id for security reason after logout
		$compositeSessionManager = $application->getCompositeSessionManager();
		//todo here was session_regenerate_id(true). Should we delete old?
		$compositeSessionManager->regenerateId();

		$response = MainContext::getCurrent()->getResponse();
		$spread = (Option::get('main', 'auth_multisite', 'N') == 'Y' ? (MainWebCookie::SPREAD_SITES | MainWebCookie::SPREAD_DOMAIN) : MainWebCookie::SPREAD_DOMAIN);

		$cookie = new MainWebCookie("UIDH", '', 0);
		$cookie->setSpread($spread);
		$cookie->setHttpOnly(true);
		$response->addCookie($cookie);

		$cookie = new MainWebCookie("UIDL", '', 0);
		$cookie->setSpread($spread);
		$cookie->setHttpOnly(true);
		$response->addCookie($cookie);

		MainCompositeEngine::onUserLogout();
	}

	$arParams["SUCCESS"] = $bOk;
	foreach (GetModuleEvents('main', 'OnAfterUserLogout', true) as $arEvent)
	{
		ExecuteModuleEventEx($arEvent, [&$arParams]);
	}

	if (Option::get('main', 'event_log_logout', 'N') === 'Y')
	{
		CEventLog::Log('SECURITY', 'USER_LOGOUT', 'main', $USER_ID);
	}
}