How to store and retrieve session value in php

Last updated on November 17th, 2015 at 05:42 am

A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application. Below script will help you understand on how to store and retrieve session value in php.

<?php
// start new session
session_start();
// add session variables
$_SESSION['type'] = "Infinity";
$_SESSION['colors'] = array("green", "white", "blue", "yellow");

if (isset($_SESSION['type']) && isset($_SESSION['colors'])) {
// do something with them
echo "You would like a " , $_SESSION['type'] , " in " ,
implode(" or ", $_SESSION['colors']);
}
?>

Here the above example will store the session named colors and display it in the output using the implode() function.

Click to rate this tutorial!
[Total: 0 Average: 0]

Leave a Reply

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