#57: Using Sessions to Temporarily Store Data

A fairly common user interface design has a user entering a fairly extensive amount of data over several forms. You also may want to store a set of data for as long as the user's browser is open (for example, for a shopping cart). Though this is technically possible with hidden form fields, it's not desirable in most cases because of its complexity and browser-state problems.

PHP has a built-in session management system that you can use to store and access data on a per-browser basis. It does most of the dirty work of setting cookies (or setting a session ID parameter) and storing the data somewhere on your server. All you need to do in your PHP scripts is start the session manager with the session_start() ...

Get Wicked Cool PHP 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.