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.


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:


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"

Table of Contents

 About This Book

 Introduction and Installation of PHP

 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

 Interface with Operating System

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Retrieving Information from HTTP Requests

Creating and Managing Sessions in PHP Scripts

 What Is a Session

 How Sessions Are Supported 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

 Managing File Upload

 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

 Parsing and Managing HTML Documents

 Configuring and Sending Out Emails

 Image and Picture Processing

 Managing ZIP Archive Files

 Managing PHP Engine and Modules on macOS

 Managing PHP Engine and Modules on CentOS

 Archived Tutorials


 Full Version in PDF/EPUB