session_start
Starts a session or resumes the existing one.
Syntax
session_start(array $options = []): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $options | array | Optional. Session settings. |
Return value
bool`true` if the session started.
Examples
A visit counter:
<?php
session_start();
$_SESSION['visits'] = ($_SESSION['visits'] ?? 0) + 1;
echo 'Visits: ', $_SESSION['visits'];Notes
Call the function at the start of every script that works with $_SESSION, and before any output to the page.
See also
- session_destroy — Deletes the session data on the server.
- session_regenerate_id — Gives the session a new identifier, keeping the data.
- setcookie — Sends a cookie to the browser.
Related recipes
In the tutorial
- Sessions and cookies — Sessions and cookies in PHP — remembering a visitor between requests, session_start, $_SESSION and setcookie.