PHP session tutorial


Home - Tutorials - Sessions

In this tutorial I will show you how to work with sessions in PHP. You will learn how to transfer information between pages.

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:

Code:
  1. ?>
If you scroll down in the output you will find a complete section with session settings like this:

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

F1 Site Family
AJAX F1
CSS F1
Database F1
Forex F1
Flash F1
HTML F1
JavaScript F1
PhotoShop F1
PHP F1
 

 
MaxTutorial
Monthly mortgage payment calculator
WebFormGenerator
Forex mini accounts

Total time: 0.0127