PHP session Tutorial


In this tutorial i exaplain how to use session in php to get value in other page.

session is a way to get value in multiple pages without passing value from one page to another.

Let Start

Filename:- form.php
<form action=”show.php” method=”post”>
<input type=”text”name=”user”>
<input type=”submit” value=”submit”>
<!--here it was just an html form to transfer value to one page to other-->

Filename :-show.php

//To use session we must start our session.session_start() is used to start our session.


//Set value in $_SESSION variable with key user now we get value from session in any page by session.

echo “Hello ”.$user;
echo “<br>”;
echo “<a href=’session.php’>Go To Next Page</a>


Filename:- session.php

//Again started session to get the value from session variable.

echo “Again Hello ”.$_SESSION[‘user’];

//here we accessing the session variable value which we set in show.php

echo “<a href=’destroy.php’>Do You Want To Destroy Session</a>”;

//session destroying link

Filename :-destroy.php

//here we destroy session by session destroy.

Thank you in next Tutorial i will share how to create a login system.
Previous Post
Next Post

post written by: