session_start()

session_start() — Start new or resume existing session.

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_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

Signature

session_start(array $options = []): bool

Parameters

ParameterTypeWhat it takes
$optionsarrayIf provided, this is an associative array of options that will override the currently set session configuration directives. The keys should not include the session. prefix.

Return value

This function returns true if a session was successfully started, otherwise false.

Example

A runnable snippet:

// page1.php session_start(); echo 'Welcome to page #1'; $_SESSION['favcolor'] = 'green'; $_SESSION['animal'] = 'cat'; $_SESSION['time'] = time(); // Works if session cookie was accepted echo '<br /><a href="page2.php">page 2</a>'; // Or maybe pass along the session id, if needed echo '<br /><a href="page2.php?' . SID . '">page 2</a>';

Changelog

VersionChange
8.5.0Now throws a ValueError if the options array has non-string keys, and a TypeError if the read_and_close value is not compatible with int.
7.1.0session_start() now returns false and no longer initializes $_SESSION when it failed to start the session.

See also

session_id()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page session_start() (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.