Help me with Php session vs Header redirect?

Posted by python on Stack Overflow See other posts from Stack Overflow or by python
Published on 2010-03-31T08:56:59Z Indexed on 2010/03/31 9:03 UTC
Read the original article Hit count: 148

Filed under:

I have the following pages:

*page1.php

<?php 
if (isset($_GET['link'])) { 
session_start(); 
$_session['myvariable'] = 'Hello World'; 
header('Location: http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']) . '/page2.php'); 
exit; 
} 
?> 
<a href="<?php print $_SERVER['REQUEST_URI'] . '?link=yes';?>">Click Here</a>

*page2.php

<?php 
print 'Here is page two, and my session variable: '; 
session_start(); 
print $_session['myvariable']; //This line could not output.
exit; 
?>

When I try output $_session['myvariable'] I did not get the result hello world message.

I could not find out the solution to fix it .?

© Stack Overflow or respective owner

Related posts about php