Firstly let us know what is session ?
Session variables hold information about one single user, and provide to all pages information in one application.
So, session basicallu store informatiom in a variable and provine in multiple page for a single user
How to start a session
session_start();
Note:- session starts Before any HTML tags.
You can see below example of session in php.
<?php
// fix session variables
$_SESSION["favcity"] = "Landon";
$_SESSION["favcountry"] = "UK";
// echo session variables
echo "Session variables will come". ".<br>";
//now here call session variables that were set on previous page
echo "Favorite city is " . $_SESSION["favcity"] . ".<br>";
echo "Favorite country is " . $_SESSION["favcountry"] . ".";
?>
Output will come:
Session variables will come.
Favorite city is Landon.
Favorite country is UK.
0 Comment(s)