PHP 8.6 Session Defaults: SameSite Lax, HttpOnly and Strict Mode, and What Breaks
Shakewell ·
PHP 8.6 changes three session defaults. session.use_strict_mode and session.cookie_httponly are now on, and session.cookie_samesite is Lax. For most sites nothing visible happens. For a site that takes a POST back from a payment gateway or a single sign-on provider, or one that sets session IDs by hand, users can be logged out or carts can empty after the upgrade.
This guide covers what php.net says changed, what breaks, how to test before you upgrade, and the correct fix against the quick revert. Everything here comes from php.net, the RFC and MDN, checked on 29 November 2026. For the other changes in this release, see our PHP 8.6 upgrade guide.
What changed in PHP 8.6 sessions
The PHP 8.6 release announcement says: “Sessions are now more secure by default: session.use_strict_mode and session.cookie_httponly are enabled, and session.cookie_samesite is set to Lax.” The migration guide’s backward incompatible changes page gives the detail.
| Setting | PHP 8.5 default | PHP 8.6 default | Who must act |
|---|---|---|---|
session.use_strict_mode |
0 |
1 |
Code or handlers that accept session IDs supplied from outside |
session.cookie_httponly |
0 |
1 |
JavaScript that reads the session cookie |
session.cookie_samesite |
unset | Lax |
Anything that needs the cookie on a cross-site POST |
The migration guide’s wording for each:
- Strict mode “rejects uninitialized session IDs, mitigating session fixation.” Handlers that relied on accepting external IDs “must either implement
SessionUpdateTimestampHandlerInterface::validateId()andSessionIdInterface::create_sid(), or explicitly set this to 0.” - HttpOnly means “session cookies are no longer accessible to JavaScript via
document.cookie. Applications that read the session cookie from JavaScript must explicitly set this to 0.” - SameSite Lax means “session cookies are no longer sent on cross-site requests other than top-level navigations using safe HTTP methods. Applications that depend on session cookies being sent on cross-site POST submissions must explicitly set this to “None” (and also set
session.cookie_secureto 1).“
The change comes from the RFC Secure Session Configuration Defaults, which targets PHP 8.6 and has the status Accepted. Each setting was voted on separately: 27 to 0 for strict mode, 26 to 0 with one abstention for HttpOnly, and 26 to 0 for SameSite Lax.
Two further session changes ship in the same release. Custom session handlers that do not implement both create_sid() and validateId() are deprecated. And when session.lazy_write is on and a handler implements SessionUpdateTimestampHandlerInterface, sessions that are empty on read and still empty at write now trigger updateTimestamp() instead of write(). A handler that relied on write() being called with empty data, for example to destroy the session, needs the same logic in updateTimestamp().
One caution: when we checked, the manual’s session runtime configuration page still listed the old defaults (Off and an empty SameSite value). The release announcement, the migration guide and the RFC are the authority for 8.6; the reference page appears to lag.
What breaks: cross-site POST, iframes, JavaScript and manual IDs
Cross-site POST callbacks. MDN says Lax sends the cookie on cross-site requests only if they are top-level navigations that use a safe method, which “excludes POST, PUT, and DELETE.” The RFC names one example: service-provider-initiated SAML single sign-on, where the identity provider POSTs back to your site. A payment gateway that returns the customer to your site with a POST is the same shape. The RFC does not mention payment gateways, so that is our reading of the rule, not a quote. When the cookie is missing, PHP sees a request with no session ID and starts a new empty session. The user looks logged out, or the cart is empty, or a CSRF check fails.
A gateway that returns the customer with a plain GET link keeps working, because a cross-site top-level GET navigation still sends a Lax cookie.
Embedded content. MDN says Lax excludes the cookie from “subresources from <img> or <script> elements, or navigations inside <iframe> elements.” If your pages are embedded in another organisation’s site, such as a booking or checkout widget in an iframe, the session cookie will not be sent from inside that frame. Test it in a browser, because php.net does not discuss iframes directly.
JavaScript that reads the cookie. With HttpOnly on, document.cookie no longer shows the session ID. The RFC says “The session ID is a server-side credential and should not be consumed by client-side code,” and recommends a separate, non-HttpOnly CSRF token instead.
Session IDs set from outside. Strict mode rejects IDs that PHP did not create. The RFC’s example is a shared-secret handoff between subdomains using the files handler, and it suggests calling session_write_close() on the originating side first. It also says custom handlers whose validateId() always returns true, such as the default Redis and Memcached handlers, are unaffected. Search for session_id( followed by a value taken from a URL, header or form field.
How to test before you upgrade to PHP 8.6
You do not need PHP 8.6 to see the effect. All three settings exist in earlier versions, so set the new values on a staging copy of your current PHP and run your flows.
session.use_strict_mode = 1
session.cookie_httponly = 1
session.cookie_samesite = "Lax"
Then work through this list:
- Check the header.
curl -sI https://staging.example.com/loginshould show aSet-Cookieline ending inHttpOnlyandSameSite=Lax. - Run every cross-site return. Complete a real test payment in the gateway’s sandbox, a full SSO login, and any other flow where another site sends the user or a form post to yours. Check the user is still logged in and the cart is intact.
- Load embedded pages inside a frame on a different test domain.
- Search the code. Look for
document.cookie,session_id(,session_set_save_handler(,SessionHandlerInterface,ini_set('session.andsession_set_cookie_params(. Code that calls these may be setting its own cookie options already, which changes what the default does. - Check queue workers and subdomains. Anything that shares sessions across hosts needs the same test.
Frameworks that run their own session layer keep their settings in their own configuration, such as config/session.php in Laravel, so check that file separately from php.ini. Any plugin or script that calls session_start() directly uses the PHP defaults.
The correct fix versus the quick revert
The quick revert is three lines in php.ini:
session.use_strict_mode = 0
session.cookie_httponly = 0
session.cookie_samesite = ""
The manual says an empty SameSite value means no attribute is set. It works, and it is sometimes the right call on release day. But it throws away the protection the PHP project added on purpose, for the whole site, to fix one flow.
| Symptom | Quick revert | Correct fix |
|---|---|---|
| Logged out after SSO or payment POST return | session.cookie_samesite = "" |
Make only the return endpoint send SameSite=None; Secure, as the migration guide says, or move to a token-based flow as the RFC suggests |
| Front-end script cannot read the session cookie | session.cookie_httponly = 0 |
Stop reading the session ID in JavaScript; issue a separate CSRF token |
| Session ID from another host is rejected | session.use_strict_mode = 0 |
Create the session on the originating side first, or implement validateId() and create_sid() in your handler |
| Custom handler deprecation notice | none needed | Implement both create_sid() and validateId() |
Our preferred fix for a POST return is to avoid needing the cookie on the POST at all. The callback endpoint checks the gateway’s signature, records the result against the order it identifies, and answers with a redirect to a normal GET page. The browser then follows it as a top-level GET navigation, which sends the Lax cookie. That is our recommendation rather than anything php.net prescribes.
If you do need SameSite=None, it must be paired with Secure, so the site must be on HTTPS. The migration guide frames it as an INI setting. The session_set_cookie_params() manual page lists only Lax and Strict for its samesite key, so set None through session.cookie_samesite in a server config scoped to the callback route, and test the resulting header.
Where we can help
We test login, checkout and single sign-on flows as part of PHP and framework upgrades, including Laravel and other framework upgrades. If you have already upgraded and users are being logged out, a project rescue review starts with the failing request and the Set-Cookie header.
Sources: PHP 8.6 release announcement, PHP 8.6 backward incompatible changes, Session runtime configuration, Securing session INI settings and session_set_cookie_params() (PHP), RFC: Secure Session Configuration Defaults (PHP wiki), Set-Cookie header (MDN) and Laravel HTTP session (all checked 29 November 2026).
Common questions
What session defaults did PHP 8.6 change?
Three. session.use_strict_mode is now 1 (was 0), session.cookie_httponly is now 1 (was 0), and session.cookie_samesite is now Lax (was unset). The PHP 8.6 migration guide lists all three under backward incompatible changes. The session.cookie_secure default is not listed as changed.
Why is login broken after upgrading to PHP 8.6?
The usual cause is SameSite=Lax. If the login or return step is a POST from another site, such as a single sign-on response, the browser no longer sends the session cookie, so PHP starts a new empty session. Check the Set-Cookie header and the request that fails, then fix that one endpoint rather than reverting every setting.
How do I revert the PHP 8.6 session defaults?
Set session.use_strict_mode = 0, session.cookie_httponly = 0 and session.cookie_samesite = "" in php.ini. The manual says an empty SameSite value means no attribute is set. This restores the old behaviour but also drops the protection the new defaults add, so we treat it as a short-term step while the real cause is fixed.
Are there other PHP 8.6 breaking changes besides sessions?
Yes. The migration guide also lists new ValueError cases for NUL bytes and invalid flags, trim() stripping form feeds, preg_grep() returning false on errors, and several deprecations such as return inside finally. Our PHP breaking changes by version guide covers them with what to search for.