php pass session to another page code example
Example 1: how to pass value from one php page to another using session
//Thanks for the answers above. Here's how I did it, I hope it helps those who follow. I'm looking to pass a registration number from one page to another, hence regName and regValue:
//Create your first page, call it set_reg.php:
<?php
session_start();
$_SESSION['regName'] = $regValue;
?>
<form method="get" action="get_reg.php">
<input type="text" name="regName" value="">
<input type="submit">
</form>
//Create your second page, call it get_reg.php:
<?php
session_start();
$regValue = $_GET['regName'];
echo "Your registration is: ".$regValue.".";
?>
<p><a href="set_reg.php">Back to set_reg.php</a>
Example 2: how to pass value from one php page to another using session
$a=$_POST['field-name'];
$a=$_SESSION['field-name];
//Before using this Syntax for creating SESSION variable we first have to add this tag at the very beginning of our php page
session_start();
//GET method are generally used to print data on same page which used to take input from user. Its syntax is as:
$a=$_GET['field-name'];