for ($i = 0; $i < $length; $i++) { $randomKey .= $chars[rand(0, strlen($chars) - 1)]; } // Return the random key return $randomKey; } // Get the session cookie name $sessionCookieName = Registry::getValue('client.session.cookie.name')->getValue(); // Make sure the session cookie is set if (!CookieManager::hasCookie($sessionCookieName)) { // Get the session timeout $sessionTimeout = Registry::getValue('client.session.timeout')->getValue(); // Generate a session key $sessionKey = generateRandomKey(); // Set the session CookieManager::setCookie($sessionCookieName, $sessionKey, $sessionTimeout); // Set the session key global $GLOBALS['session_key'] = $sessionKey; } /** * Get the key of the current client session. * * @return string Session key * * @throws Exception Throws if an error occurred. */ function getSessionKey() { // Return the key from the globals if set if (isset($GLOBALS['session_key'])) { return $GLOBALS['session_key'];
/** * Set the language tag cookie. * * @param string|null $langTag The language tag, or null to reset. * * @throws Exception Throws if the language tag is unknown or invalid. */ public static function setCookieLanguageTag($langTag) { // Make sure the tag is valid or null if ($langTag !== null && !static::isWithTag($langTag)) { throw new Exception('Invalid or unknown language tag.'); } // Set or reset the cookie if ($langTag !== null) { CookieManager::setCookie(static::LANGUAGE_COOKIE_NAME, $langTag, static::LANGUAGE_COOKIE_EXPIRE); } else { CookieManager::deleteCookie(static::LANGUAGE_COOKIE_NAME); } }