PHP session

PHP session is used to store data on server side insted of client side. sessions is better than cookies because session strores data on server side and cookies stores data on computer browser. Anybode can get cookies data from browser. So security data should not be strored by cookies.

PHP session function :
1. session_start() - It is used to start new session.
2. session_destroy()- It is used to destory all session variables completely.
3. session_id() - It generates current new unique session id.
PHP $_SESSION Variable :
 $_SESSION is session variable which used to assign and retrive value.

Look at below example where username and email id are strored by session variable.
<?php
session_start();
$_SESSION['username']="Robert";
$_SESSION['email']="Robert*****@yah**o.com";

?>
Now you can get above values as per as below.

<?
session_start();

echo "<br>User Name:".$_SESSION['username'];

echo "<br>Email:".$_SESSION['email'];
session_destroy();

?>

Output :

User Name:Robert
Email:Robert*****@yah**o.com

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

95455