When one page is accessed, I would like to start a session and store a session variable:
<?php
session_start();
$_SESSION['myvar']='myvalue';
?>
Then from another page, I would like to check if that session variable has been stored:
<?php
session_start();
echo("1");
if(isset($_SESSION['myvar']))
{
echo("2");
if($_SESSION['myvar'] == 'myvalue')
{
echo("3");
exit;
}
}
?>
This code does not work for me.
Defining session before everything, No output should be before that, NO OUTPUT
<?php
session_start();
?>
Set your session inside a page and then you have access in that page. For example this is page 1.php
<?php
//This is page 1 and then we will use session that defined from this page:
session_start();
$_SESSION['email']='[email protected]';
?>
Using and Getting session in 2.php
<?php
//In this page I am going to use session:
session_start();
if($_SESSION['email']){
echo 'Your Email Is Here! :) ';
}
?>
NOTE: Comments don't have output.