PHP session tutorial
In this tutorial I will show you how to work with sessions in PHP. You will learn how to transfer information between pages.
Tutorial info:
Name: | PHP session tutorial |
Total steps: | 5 |
Category: | Sessions |
Level: | Beginner |
Bookmark PHP session tutorial

Step 1 - Session basics
PHP session tutorial
As you may know HTTP is a stateless protocol which means that each server request knows nothing about the others. What does it mean in our case?
Suppose a login system where a visitor can log in and the logged in users have more rights on the site. It means that the login page, let's say login.php has information about the user. However if the user visits a page eg.: myprofile.php then you lose all of the data you have on login.php. So on each page load all old datav will be lost.
To solve this problem the sessions were introduced in PHP. Using sessions you can transfer data between various pages. If you are using sessions then each of your visitors will got a unique id. This id will identify various visitors and with the help of this id are the user data stored on the server.
Session handling can be fine tune with PHP parameters. Just run the following small code and you will get you actual PHP settings:
session
Session Support | enabled |
Registered save handlers | files user |
Registered serializer handlers | php php_binary wddx |
Directive | Local Value | Master Value |
---|---|---|
session.auto_start | Off | Off |
session.bug_compat_42 | Off | Off |
Next Step of PHP session tutorial
Tags: php sessions, php, session, session handling
PHP session tutorial - Table of contents |
---|
Step 1 - Session basics |
Step 2 - Most important session parameters |
Step 3 - Starting a session |
Step 4 - Check sessions |
Step 5 - Clean and destroy session |