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.

Tutorial info:

Name:PHP session tutorial
Total steps:5

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:

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


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

Follow phpf1 on Twitter

F1 Site Family
Java F1
JavaScript F1

Total time: 0.1453