In: PHP
21 Sep 2009Session is global variable which mainly use to send data from one page to another. Session variables allow you to store “global” data for use by all your pages and are specific or unique to each visitor to your site.” 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.”
Starting Session
session_start() creates a session or resumes the current one based on the current session id that’s being passed via a request, such as GET, POST, or a cookie.
Example:
<?php session_start(); $_SESSION['name']='data you want to store'; ?>
Session Variable should use before <html> tag.
Print Session Variable:
<?php echo $_SESSION['name']; ?>
Or can be assign to any other variable names:
<?php $username=$_SESSION['name']; ?>
Destroy a Session
To destroy any specific session use unset function.
<?php unsert($_SESSION['name']); ?>
To destory all session variables use destroy function.
<?php session_destroy(); ?>
