Logo Logo
Back to list
Razno

Understanding and Configuring the SameSite Cookie Attribute

14. 03. 2026
Understanding and Configuring the SameSite Cookie Attribute

Browsers have recently tightened security measures. If you see a warning regarding the SameSite attribute on your site, it means you must explicitly tell the browser how to handle your cookies in different contexts.

What is SameSite?

The SameSite attribute in the HTTP cookie header controls when a cookie is sent to the server. Its main purpose is to protect against:

  • CSRF Attacks: Prevents malicious sites from exploiting your active user session.
  • Information Leakage: Limits the sharing of cookies across different domains.

Possible Attribute Values

  1. Strict: The strictest setting. The cookie is only sent if the request originates from the same domain.
  2. Lax: The safe default. The cookie is sent during navigation within the same domain and for some top-level external links, but not in iframes.
  3. None; Secure: The cookie is always sent, including in third-party contexts. Required to be used with a secure HTTPS connection.

How to Solve it in Code

PHP (7.3+)

setcookie("PH_HPXY_CHECK", "value", [
"SameSite" => "None",
"Secure" => true, // Mandatory for None
"HttpOnly" => true
]);

JavaScript

document.cookie = "PH_HPXY_CHECK=value; SameSite=None; Secure";

Nginx / Apache

If setting cookies at the server level:

# Nginx
add_header Set-Cookie "PH_HPXY_CHECK=value; Path=/; SameSite=None; Secure";
Apache

Header always add Set-Cookie "PH_HPXY_CHECK=value; Path=/; SameSite=None; Secure"

Hvala za obisk! Dodajam politiko zasebnosti.

© 2024 Vse pravice pridržane.

Vam je koda pomagala? Če želite podpreti moj trud pri pripravi vodičev in vzdrževanju strani, mi lahko namenite donacijo za kavo.