Share on Google+Share on Google+
PHP Session
Posted on: March 31, 2010 at 12:00 AM
Advertisement
In this tutorial we will study about session, what is session, how PHP handles session etc. In PHP $_SESSION is a pre-defined variable, this variable is used to store different values, which are accessible from any page of the website. Examples in this tutorial will make it more clear.

Session:

A session variable is used to store some useful data and that data is accessible from every page. In PHP $_SESSION is a pre-defined variable, this variable is used to store different values, which are accessible from any page of the website.

When we develop an application (website etc.), user access it, do their tasks and close it. It is a Session. A computer could know us, but on the Internet the web server does not know who we are and what we do because the HTTP is a stateless protocol.

A session helps us to fix this problem by allowing us to store useful data on the server. Data stored in session is temporary and deleted after the user has left the website.

Session produces a unique id (UID) for each visit and we may take reference of it as per requirement. The session_start() function must appear at the beginning of coding (before html).

Example:

<?php

session_start();

if(isset($_SESSION))$_SESSION['view']+=1;

else $_SESSION['view']=1;

echo "Total no. of view is:".$_SESSION['view'];

?>

Output:

Total no. of view is:3

Advertisement

Related Tags for PHP Session:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 31, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com