session_id()
session_id() — Get and/or set the current session id.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
session_id() is used to get or set the session id for the current session.
Signature
session_id(?string $id = null): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $id | ?string | If id is specified and not null, it will replace the current session id. session_id() needs to be called before session_start() for that purpose. Depending on the session handler, not all characters are allowed within the session id. For example, the file session handler only allows characters in the range [a-zA-Z0-9,-]! |
Return value
session_id() returns the session id for the current session or the empty string ("") if there is no current session (no current session id exists). On failure, false is returned.
Example
The PHP manual ships no example for session_id(); the signature and the parameter table above are the contract.
Changelog
| Version | Change |
|---|---|
| 8.0.0 | id is nullable now. |
See also
session_regenerate_id(), session_start(), session_set_save_handler()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page session_id() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.