PHPSESSID is the default cookie name PHP uses to send a browser’s session ID. The ID is a key to session data stored on the server; it is not the session data itself. PHP can also transport IDs in URLs, but that is a riskier fallback and should generally be avoided.
How a PHP session works
An application can use a PHP session to retain state between requests, such as whether a visitor is signed in. The server stores the session data and gives the browser a session ID. On a later request, the browser sends that ID back, and PHP uses it to find the corresponding data. By default, the ID is sent in a cookie named PHPSESSID; applications can change the name through configuration or session_name(). PHP session configuration
That distinction matters: the cookie contains the identifier, not the stored session contents. If the browser stops sending the right ID, PHP may not be able to associate a request with the earlier session.
Cookie or URL: how PHP transports the session ID
| Method | How it works | Exposure and use |
|---|---|---|
| Cookie | The browser returns the session ID in a cookie on later requests. | Recommended default. Cookie attributes can restrict where the ID is sent and whether JavaScript can read it. |
| URL | When transparent SID support is enabled, PHP can accept or rewrite URLs that contain a session ID. | Higher risk: IDs can end up in shared or bookmarked links, browser history, referrers, and logs. Consider only as a narrowly assessed compatibility fallback. |
The PHP manual warns: “URL based session management has additional security risks compared to cookie based session management.” The session.use_trans_sid setting, which enables transparent URL-based session ID support, defaults to disabled and is deprecated as of PHP 8.4.0. PHP session security settings PHP session configuration
#1 Best Overall
Older forum advice about manually appending a session ID to links reflects earlier PHP practice, not a good modern default. A SitePoint discussion dated May 19, 2001 distinguishes session data from its ID, but its URL advice should be read in its historical context. SitePoint forum discussion
Why a PHP session may not continue between pages
For a cookie-based session to continue, the browser must receive the session cookie and send it on the next request to a scope where that cookie applies. If the ID is missing or changes, PHP may treat the request as a different session. Check the cookie and its scope—domain, path, HTTPS requirements, and SameSite behavior—along with the application’s session setup. PHP documents the relevant cookie and session options in its session configuration reference.
Rank #2
- Cookie not accepted or returned: browser privacy settings, extensions, or application behavior may prevent the cookie from being stored or sent.
- Scope mismatch: a cookie set for one path or host may not apply to another; a Secure cookie is sent only over HTTPS.
- Identifier handling differs: code or configuration may change the session name or cookie options between requests.
- Session lifecycle changes: application code may explicitly destroy, replace, or expire a session.
Inspect the response that starts the session for a Set-Cookie header, then check whether the browser includes that cookie in the next request. Do not copy or publish the session ID while debugging: possession of an active ID can enable someone else to use the session.
Secure PHP session configuration
PHP’s security guidance recommends cookie-only ID management and strict mode. In configuration, the core settings are session.use_cookies=On, session.use_only_cookies=On, and session.use_strict_mode=On. Strict mode rejects uninitialized session IDs, helping reduce session-fixation risk. Set cookie protections appropriate to the deployment: HttpOnly to prevent JavaScript access, Secure for HTTPS-only sites, and an appropriate SameSite value. PHP session security settings PHP session security
Quick Recap
Rank #4
- Treat session IDs as bearer credentials: anyone who obtains an active ID may be able to act as that session.
- Do not put IDs in page content, URLs, logs, or links that can be shared with other sites.
- Regenerate the session ID when a user authenticates or changes privilege; invalidate old sessions when the application’s security requirements call for it.
- Choose cookie domain, path, Secure, HttpOnly, and SameSite settings to match the site’s hosts, routes, HTTPS use, and cross-site needs.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

