© Mikael Olsson 2016

Mikael Olsson, PHP 7 Quick Scripting Reference, 10.1007/978-1-4842-1922-5_25

25. Sessions

Mikael Olsson

(1)Hammarland, Finland

A session provides a way to make variables accessible across multiple web pages. Unlike cookies, session data is stored on the server.

Starting a Session

To begin a session, the session_start function is used. This function must appear before any output is sent to the web page.

<?php session_start(); ?>

The session_start function sets a cookie on the client’s computer, containing an id used to associate the client with the session. If the client already has an ongoing session, the function resumes that session instead of starting a new one.

Session Array

With the session started, the $_SESSION array is used ...

Get PHP 7 Quick Scripting Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.