PHP session Tutorial - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript PHP session Tutorial - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Monday, March 27, 2017

PHP session Tutorial


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
<html>
<head></head>
<body>
<form action=”show.php” method=”post”>
<label>User</label>
<br>
<input type=”text”name=”user”>
<br>
<input type=”submit” value=”submit”>
<!--here it was just an html form to transfer value to one page to other-->
</form>
</html>


Filename :-show.php
<?php
session_start();

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

$user=$_REQUEST[‘user’];
$_SESSION[‘user’]=$user;

//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
<?php
session_start();

//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

<?php
session_start();
session_destroy();
//here we destroy session by session destroy.
?>


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

No comments:

Post a Comment

Post Top Ad