3declare(strict_types=1);
14use TYPO3\CMS\Core\Exception;
15use TYPO3\CMS\Core\Log\LogLevel;
16use TYPO3\CMS\Core\Utility\GeneralUtility;
37 $cookieDomain = $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'cookieDomain'];
40 if (!empty($GLOBALS[
'TYPO3_CONF_VARS'][
'FE'][
'cookieDomain'])) {
41 $cookieDomain = $GLOBALS[
'TYPO3_CONF_VARS'][
'FE'][
'cookieDomain'];
44 if ($cookieDomain[0] ===
'/') {
46 $matchCnt = @preg_match($cookieDomain, GeneralUtility::getIndpEnv(
'TYPO3_HOST_ONLY'), $match);
47 if ($matchCnt ===
false) {
50 'getCookieDomain: The regular expression for the cookie domain contains errors. The session is not shared across sub-domains.',
52 'cookieDomain' => $cookieDomain,
53 'errorCode' => 1399137882,
56 } elseif ($matchCnt) {
60 $result = $cookieDomain;
77 setcookie($cookieName);
90 public function setCookie(
string $cookieName,
string $cookieValue, $cookieExpire = 0): void
94 if (!empty($cookieExpire)) {
95 $settings = $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'];
102 $cookiePath = ($cookieDomain ?
'/' : GeneralUtility::getIndpEnv(
'TYPO3_SITE_PATH'));
108 $cookieSecure =
false;
109 if (array_key_exists(
'cookieSecure', $settings)) {
110 $cookieSecure = (bool)$settings[
'cookieSecure'] && GeneralUtility::getIndpEnv(
'TYPO3_SSL');
113 $cookieHttpOnly =
true;
114 if (array_key_exists(
'cookieHttpOnly', $settings)) {
115 $cookieHttpOnly = (bool)$settings[
'cookieHttpOnly'];
119 if (!($cookieSecure xor GeneralUtility::getIndpEnv(
'TYPO3_SSL'))) {
131 'setCookie: Cookie set',
133 'cookieName' => $cookieName,
134 'cookieValue' => $cookieValue,
135 'cookieExpire' => $cookieExpire,
136 'cookiePath' => $cookiePath,
137 'cookieDomain' => $cookieDomain,
138 'cookieSecure' => $cookieSecure,
139 'cookieHttpOnly' => $cookieHttpOnly,
144 'Cookie was not set since HTTPS was forced in $TYPO3_CONF_VARS[SYS][cookieSecure].',
160 return isset($_COOKIE[$cookieName]) ? stripslashes($_COOKIE[$cookieName]) :
null;
172 return !empty($this->
getCookie($cookieName));
clearCookie(string $cookieName)
hasCookie(string $cookieName)
getCookie(string $cookieName)