Answers for "php send values in $_SESSION to other page"

PHP
1

php send values in $_SESSION to other page

<?php
//PAGE 1
// Start the session
session_start(); //<- IMPORTANT TO SET IT AT THE TOP IN PAGE 1
?>
<!DOCTYPE html>
<html>
<body>

<?php
// Set session variables
$_SESSION["favcolor"] ="green";
$_SESSION["favanimal"] ="cat";
echo "Session variables are set.";
?>
---------------------------------------------------------------
<?Php
//Page2:
session_start(); //<- IMPORTANT TO SET IT AT THE TOP IN PAGE 2
echo "my favcolor is".$_SESSIO["favcolor"];/*here it will display my fav color is green*/
?>
Posted by: Guest on October-11-2021
0

how to pass value from one php page to another using session

//There are three method to pass value in php.

//By post
//By get
//By making session variable
//These three method are used for different purpose.For example if we want to receive our value on next page then we can use 'post' ($_POST) method as:-

$a=$_POST['field-name'];
//If we require the value of variable on more than one page than we can use session variable as:-

$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'];
//POST method are generally consume more secure than GET because when we use Get method than it can display the data in URL bar.If the data is more sensitive data like password then it can be inggeris.
Posted by: Guest on July-20-2020

Browse Popular Code Answers by Language