PHP Tutorials - Herong's Tutorial Examples - v5.17, by Herong Yang
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"
Table of Contents
Introduction and Installation of PHP
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
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
How Sessions Are Supported in PHP
SessionPage*.php - Session Test Script Pages
Running Session Test Script Pages
Managing Session IDs without Cookies
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
Parsing and Managing HTML Documents
Configuring and Sending Out Emails
Managing PHP Engine and Modules on macOS