PHP : Cookies and Sessions
$_SESSION: By using this super global variable, we can read the values of sessions and also we can creat the sessions.
*Sessions resides in web server.
Difference between Cookies and Sessions:
| · Cookies reside in client system. · Cookies are unsecured. · Cookies stores limited data of amount. · Cookies can store only string data. · Cookies are burden to the client system | ·Resides in web server · Highly secured ·Sessions ca store huge amount of data ·Sessions can store any type of data ·Burden to web server. |
*By default sessions will not initialize in temporary location. To initialize the sessions we use “sessions.auto_start” configuration directive. This directive is used to initialize the sessions when he request is started.
*If you want to transform the sessions value from one page to another page with irrespective of session.auto_start. We have to use this function in the page.
Program:
Page1.php
<?php
session_start();
$x=10;
$_SESSION['lan']="php";
echo $x;
echo $_SESSION['lan'];
?>
<a href="page2.php">got to </a>
session_start();
$x=10;
$_SESSION['lan']="php";
echo $x;
echo $_SESSION['lan'];
?>
<a href="page2.php">got to </a>
Page2.php
<?php
session_start();
echo "value of x is".$x;
echo "value of session is".$_SESSION['lan'];
session_start();
echo "value of x is".$x;
echo "value of session is".$_SESSION['lan'];
?>
Note: if we use “session.auto_start we can access the application else if we use session_start>we can success only page values.
No comments:
Post a Comment