arrow left
arrow right
World of RS Furniture  Surgical Instruments Exporters Job Search Discussion Forum online Website Translators Maithili Society and Culture Movers and Packers Directory Online Property Furnishing Services Automotive PR agency Luxury Tailored Coats Video Production and DVD Filming Tour and Travel Directory Music libraries online Professional Community Portal Manufacturer of automotive bearings office jobs delhi WEBSITE DESIGNING COMPANY IN INDIA online tour operator of India Freelance Automotive Journalism Engineering Works India Truck Transport India Indian php programming firm NGO in India Professional Business Services Car Hire Company India B2B Trade Directory Indian Tour Operator Electronic Products Catelogue JHV Booth Online Indian B2B Directory STRANCO ABITA SPRINGS Bikini Selling Online

Tutorial of Session in PHP

In this article we will discuss what are Sessions and how to work with sessions in PHP

Software >> PHP Programming

Overview: In this article we will discuss what are Sessions and how to work with sessions in PHP.

Imagine that you have some data about a particluar user and this information you need on all of the pages, woudn't it be great if you could store that info in a variable and

access it from any page, Sessions exactly do that.

Using sessions you could hold data about particluar user and access that info on all the pages as long as the user is active on the site.

* Each session holds different values for different user.
* Sessions automatically die when the users session is over or he closes his browser.

PHP's session-handling features, was first introduced in the 4.0 release. Sessions are native and thus require no additional packages.

To work with Sessions we will be using session_start() and session_register() functions, its important that you add sesions_start to every page where you would like to

use sessions. I will explain you the conecpt with an example.

session1.php
<?
// create a new session
session_start();

// register a session-variable
session_register("color"); //we have created a session with name color

$color = "blue"; //assigning some value to our session
?>
Go to another session-enabled page.

Okay now we have created a session with name color and assigned it as blue, now in our second program (session2.php) we access the value of our session color

session2.php
<?php
session_start();

echo "The value stored in your session: " $color; //retriving value from the session
?>

To delete a session variable we use the function session_unregister(), so to delete our session color we would use the code

<?
session_unregister(color);
?>