|
|
Session and storing, retrieving values - PHP
|
Views : 386
|
|
Tagged in : PHP
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
A session is used in php to temporarily store values as variables in the server.
A session value once stored will be available until
- the browser is closed
- session timeout is reached
- you remove the value from the session.
Unlike a cookie, the value is not stored on the users computer.
Starting a session:
You have to start a session to insert values in to the session
<?php
session_start();
// this function should be the first line on you page where you are to store the value.
?>
Storing a value:
Now we are to start a session and set a value in to a variable from a php page (say x.php).
<?php
session_start();
// setting values in to the session as variables
$_SESSION['test']='my value';
?>
Retriving a Value:
Consider we need that value in a different page (say y.php).
The code will be as follows
<?php
session_start();
// session_start should always be the first line of code in you php page
//retrieving or getting the stored session value
echo "Stored value is ".$_SESSION['test'];
|
|
By rajesh, On - 2009-10-29 |
|
|
|