Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 8432 cookie php73 #8436

Merged
merged 3 commits into from Feb 13, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 29 additions & 11 deletions app/bundles/CoreBundle/Helper/CookieHelper.php
Expand Up @@ -18,7 +18,8 @@
*/
class CookieHelper
{
const SAME_SITE_NONE = '; samesite=none';
const SAME_SITE = '; samesite=';
const SAME_SITE_VALUE = 'none';
private $path = null;
private $domain = null;
private $secure = false;
Expand Down Expand Up @@ -79,19 +80,36 @@ public function setCookie($name, $value, $expire = 1800, $path = null, $domain =

// If https, SameSite equals None
$sameSiteNoneText = '';
$sameSiteNoneTextGreaterPhp73 = null;
if ($secure === true or ($secure === null and $this->secure === true)) {
$sameSiteNoneText = self::SAME_SITE_NONE;
$sameSiteNoneText = self::SAME_SITE . self::SAME_SITE_VALUE;
$sameSiteNoneTextGreaterPhp73 = self::SAME_SITE_VALUE;
}

setcookie(
$name,
$value,
($expire) ? (int) (time() + $expire) : null,
(($path == null) ? $this->path : $path).$sameSiteNoneText,
($domain == null) ? $this->domain : $domain,
($secure == null) ? $this->secure : $secure,
($httponly == null) ? $this->httponly : $httponly
);
if (version_compare(phpversion(), '7.3', '>=')) {
setcookie(
$name,
$value,
($expire) ? (int) (time() + $expire) : null,
(($path == null) ? $this->path : $path).$sameSiteNoneText,
($domain == null) ? $this->domain : $domain,
($secure == null) ? $this->secure : $secure,
($httponly == null) ? $this->httponly : $httponly,
[
'samesite' => $sameSiteNoneTextGreaterPhp73
]
);
} else {
setcookie(
$name,
$value,
($expire) ? (int) (time() + $expire) : null,
(($path == null) ? $this->path : $path),
dennisameling marked this conversation as resolved.
Show resolved Hide resolved
($domain == null) ? $this->domain : $domain,
($secure == null) ? $this->secure : $secure,
($httponly == null) ? $this->httponly : $httponly
);
}
}

/**
Expand Down