Bear with me if this looks similar to other questions posted here, I have already gone through all answers provided but not has solved my problem. I've reduced my problem to the bare minimum.
- I have two pages (page1.php, page2.php)
- Page1.php creates a session variable and if the session variable is set it then sends the browser to Page2.php
- On page2.php the browser is supposed to display the value of the session variable set in Page1. php
- My problem is that page2.php views the session variable as not set.
- I have tried all the solutions posted by other users on stack overflow as you can see from my code below:
Page1.php
<?php
//start the session
session_start();
//set the session
$_SESSION['mysession'] = "Hello";
if(isset($_SESSION['mysession'])){
//redirect the person to page 2
session_write_close();
header("Location: page2.php?PHPSESSID=".session_id());
exit();
} else {
echo "Session Not Set";
}
?>
Page2.php
<?php
//start the session
session_start();
session_id($_GET['PHPSESSID']);
if ( isset ($_SESSION['mysession']) )
echo $_SESSION['mysession'];
else
echo "Session not set!";
?>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…