How to Fix warning: Cookie “” will be soon rejected because it has the “sameSite” attribute set to “none” or an invalid value

If you have noticed this warning in your developer's console, then you are not alone. The browser will soon require you to set this for cookie security reasons. The general warning looks like this: 

Cookie “PHPSESSID” will be soon rejected because it has the “sameSite” attribute set to “none” or an invalid value, without the “secure” attribute

From now on when setting your cookies you will need to set the samesite attribute.

For example, for older versions of PHP you will need to set them like the following:

session_start();

$session = session_id();

setcookie('Members_Session', $session, 0, '/; samesite=Lax');

For PHP versions 7+ you can use the following to set cookies:

setcookie('Members_Session', $session , ["path"=>"/",'samesite' => 'Lax']);

The value used depends on your site's requirements. More information can be found here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite

 

 

Comments

Popular posts from this blog

Build 6 is here

An example of chaining jQuery Ajax request callbacks

Creating hashtag hyperlinks on the fly for your website