The browser warns about a SameSite cookie set from PHP
A cookie without a SameSite attribute triggers a browser warning in the consoleShort answer
A cookie sent without a SameSite attribute gets the browser's default, and a cookie marked None is dropped unless it is also Secure. In PHP 7.3 and later, pass an options array to setcookie() with samesite and secure set. Choose Lax or Strict when the cookie is not needed cross-site.
Fix it fast
1Find out which cause you have
Look at the Set-Cookie header the server really sends. It shows whether SameSite and Secure are present.
curl -s -D - -o /dev/null https://example.com/login | grep -i set-cookie2Match what you see, then jump to its fix
- 1
The Set-Cookie header has no SameSite partsetcookie() is called without a SameSite attributeFix - 2
The cookie is blocked in a cross-site embed or requestSameSite=None without the Secure attributeFix - 3
Secure cookies never appear on http:// pagesThe Secure attribute is set but the site is plain HTTPFix - 4
PHPSESSID is the cookie the browser complains aboutThe PHP session cookie has no SameSite valueFix
- 1
What does the error look like?
A cookie without a SameSite attribute triggers a browser warning in the consoleA cookie with SameSite=None is rejected because it lacks the Secure attribute
Cause 1 of 4
setcookie() is called without a SameSite attribute
1Check
If the samesite element is omitted, PHP sets no SameSite attribute, and the browser applies its own default. Some browsers treat a missing value as Lax.
grep -rn "setcookie(" --include=*.php . | head2Fix
Use the options-array form (PHP 7.3 and later) and set samesite to Lax, Strict or None.
setcookie('prefs', $value, [
'expires' => time() + 3600,
'path' => '/',
'secure' => true,
'httponly' => true,
'samesite' => 'Lax',
]);3Verify
The header should now end with SameSite=Lax.
curl -s -D - -o /dev/null https://example.com/login | grep -i set-cookieConfirmed by php.net
Cause 2 of 4
SameSite=None without the Secure attribute
1Check
None sends the cookie on cross-site requests too, and the Secure attribute must also be set with it. PHP's manual says that with None, a cookie without Secure will be blocked by the client.
curl -s -D - -o /dev/null https://example.com/login | grep -i "samesite"2Fix
Set secure to true together with samesite None, and serve the site over HTTPS.
setcookie('widget', $value, [
'path' => '/',
'secure' => true,
'samesite' => 'None',
]);3Verify
Reload the page that embeds the cookie and check it is accepted.
curl -s -D - -o /dev/null https://example.com/login | grep -i set-cookieConfirmed by developer.mozilla.org
Cause 3 of 4
The Secure attribute is set but the site is plain HTTP
1Check
A Secure cookie is only sent over https, and an insecure http page cannot set one, except on localhost.
curl -I http://example.com | head -n 12Fix
Serve the site over HTTPS. For local work use localhost, which is exempt.
# serve the page over https, or use http://localhost for local work3Verify
The cookie shows up in the browser's storage panel.
curl -k -s -D - -o /dev/null https://localhost/login | grep -i set-cookieConfirmed by developer.mozilla.org
Cause 4 of 4
The PHP session cookie has no SameSite value
1Check
session.cookie_samesite defaults to an empty string, which means no SameSite attribute is set. The manual lists Lax and Strict for it.
php -r 'echo ini_get("session.cookie_samesite");'2Fix
Set it in php.ini, or call session_set_cookie_params() with an options array before session_start().
session_set_cookie_params([
'lifetime' => 0,
'path' => '/',
'secure' => true,
'httponly' => true,
'samesite' => 'Lax',
]);
session_start();3Verify
The PHPSESSID cookie in the response should now carry SameSite=Lax.
curl -s -D - -o /dev/null https://example.com/login | grep -i phpsessidConfirmed by php.net
How do I stop it coming back?
- Set SameSite explicitly on every cookie instead of relying on browser defaults.
- Use Lax or Strict unless a cross-site embed really needs the cookie.
- Check the Set-Cookie header after every change, not only the browser UI.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Security
Laravel answers a form or AJAX call with 419 Page Expired
419 Page Expired (a POST, PUT, PATCH or DELETE request)
Laravel could not match the CSRF token in your request to the one stored in the visitor's session.
5 causes, each with a fixSecurity
PHP LDAP in Laravel fails with Can't contact LDAP server over TLS
unable to get local issuer certificate
PHP's LDAP client uses OpenLDAP's settings.
3 causes, each with a fixSecurity
Is my PHP application affected by PHP2Shell, and how do I mitigate it?
A scanner or advisory feed reports CVE-2026-109619 (RCE via stale global state) on your server
You are exposed when the PHP serving web requests is older than 8.2.35, 8.3.36, 8.4.27 or 8.5.12 on its branch, or when a distribution package is older than its vendor's fixed build.
6 causes, each with a fixSecurity
Entra ID token request fails: the request body must contain the parameter 'grant_type'
AADSTS900144: The request body must contain the following parameter: 'grant_type'.
The token endpoint did not find grant_type in the form body of your POST.
3 causes, each with a fixSecurity
Angular HttpClient does not add the X-XSRF-TOKEN header to a request
403 Forbidden on POST, PUT or DELETE while GET works
Angular copies the XSRF-TOKEN cookie into an X-XSRF-TOKEN header only for mutating requests to the same origin, and only when the cookie is readable by script.
5 causes, each with a fixSecurity
An [Authorize] endpoint rejects a request with a bearer token
Authorization Header sent: no Bearer token sent.
An [Authorize] endpoint without a policy name requires an authenticated user.
4 causes, each with a fix