PHP Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 3.10

Where Is Session Data Stored?

This section provides a tutorial example on how to find out where the PHP engine stores session data. The session.save_path setting specifies the directory name for session data.

Where does PHP store session data? The answer is not so obvious.

Since I am running the PHP engine in CGI mode, PHP script pages are running with individual instances of the PHP executable program. So there is no easy to store session data in memory and share it between different PHP script pages. If not stored in memory, session data can be stored on hard disk and share it between PHP pages. Let's see if we can find where session data is stored on the hard disk.

First run http://localhost/SessionPage1.php again:

I am buying 3 PHP books.

Next

Counter = 1
Session name = PHPSESSID
Session id = mg04r204ctuloo2uegmih14ri5
Session module = files

Contents of $_GET:

Contents of $_POST:

Contents of $_COOKIE:

Then use the Windows find tool to search for file names with "mg04r204ctuloo2uegmih14ri5". No surprise, you should get \tmp\sess_mg04r204ctuloo2uegmih14ri5. Open this file in a text editor, you should see:

quantity|i:3;count|i:1;

The file format is so simple, session data is stored in clear text, with ";" as delimiters. If you want to change where session data is stored, you can modify the session.save_path setting in \php\php.ini. For example:

session.save_path = "\herong\temp"

Last update: 2005.

Table of Contents

 About This PHP Tutorial Book

 Introduction and Installation of PHP 5.4.3

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Configuring and Sending out Emails

 Retrieving Information from HTTP Requests

Creating and Managing Sessions in PHP Scripts

 What Is a Session?

 How Sessions Are Support in PHP?

 SessionPage*.php - Session Test Script Pages

 Running Session Test Script Pages

 Managing Session IDs without Cookies

Where Is Session Data Stored?

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Outdated Tutorials

 References

 PDF Printing Version

Dr. Herong Yang, updated in 2012
Where Is Session Data Stored?