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);
?>
-
Lastest Articles
10 principles of search engine friendly web design
Search engine friendly web design is web design that is planned around known search engine optimization principles. If ranking well in the search engines is important to you then the first step towards6 tips to improve results from your website
Make sure you know why you want a website and what you want your website to do for you. Write down some broad goalsCross Browser Compatibility
there are really only two types of browsers you need to consider. If you run a fairly standard website, these will probably account for 99% of your audienceHow to get the Web 2.0 Look and Feel
refers to the new wave of community driven websites, it is also increasingly used to describe the fresh and clean design approach they useRevealing Facebook Application XSS Holes
Beginning tomorrow, September 1st, I will begin posting full technical details of cross-site scripting vulnerabilities that I have discovered in Facebook applicationsFacebook Applications are Now Even More Valuable Hacking Targets
which I called a FAXX hack, enables one to not only post links to Facebook for viral effects but also harvest a wealth of information on victimized users along the wayNew Trick to View Hidden Facebook Photos and Tabs
Last December, I posted a bit of JavaScript known as a bookmarklet that allowed you to see photo albums for any Facebook user if the album privacy settings allowed itUsing Google Buzz Can Expose Your Gmail Address
In short, having a public Google profile (which you might have created when checking out Google Buzz) can allow others to figure out your Gmail addressGoogle Takes Small Steps for Buzz, Points to Big Solutions for Social Networking
Buzz, Google's controversial attempt to unseat Facebook as the most mainstream of social activity stream readers, just made some much-needed changes that Facebook could learn from as wellGet Satisfaction Turns Facebook Fan Pages into Customer Support Hubs
Get Satisfaction, the popular online customer service company, just announced that it is bringing its service to Facebook fan pages


























