session_name

FunctionParams and return types changed in PHP 8.0

Get and/or set the current session name.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

session_name Function synopsis

session_name(?string $name = null): string|false

Parameters

$name

OptionalType?stringDefault valuenull

The session name references the name of the session, which is used in cookies and URLs (e.g. PHPSESSID). It should contain only alphanumeric characters; it should be short and descriptive (i.e. for users with enabled cookie warnings). If $name is specified and not null, the name of the current session is changed to its value.

Return value

Typestring|false

Returns the name of the current session. If $name is given and function updates the session name, name of the old session is returned, or false on failure.

Changes to the session_name Function

PHP 8.0

  • Return type added: string|false
  • Parameter type added for parameter #1 ($name): ?string
  • Parameter default value added for position #1 ($name): null
- session_name($name)
+ session_name(?string $name = null): string|false

session_name Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes