CHAPTER 25

image

Sessions

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 send to the web page.

<?php session_start(); ?>

The session_start function will set 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 will resume that session instead of starting a new one.

Session array

With the session started the $_SESSION array can be used to store ...

Get PHP Quick Scripting Reference 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.