Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

session_start

Starts a session or resumes the existing one.

Syntax

session_start(array $options = []): bool

Parameters

ParameterTypeDescription
$optionsarrayOptional. 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

Related recipes

In the tutorial

  • Sessions and cookies — Sessions and cookies in PHP — remembering a visitor between requests, session_start, $_SESSION and setcookie.

Thanks for reading!

Donate to the site — we work hard for you.