Forum Moderators: coopster
page 1
========
//i define variables based on values posted from a form on the same page using PHP_SELF, run a couple of checks and redirect to page 2 using header()
<?php
session_start();
$name = htmlspecialchars($_POST['name']);
$lname = htmlspecialchars($_POST['lname']);
$_SESSION['name'] = $name;
$_SESSION['lname'] = $lname;
....
?>
page 2
========
echo $_SESSION ['name'] works just fine....
//then i define new variables on page 2 using the same method and redirect to page 3
<?php
session_start();
//new variables
$co = htmlspecialchars($_POST['co']);
$_SESSION['co'] = $co;
....
?>
page 3
========
echo $_SESSION['co'] shows the value of $co, but $_SESSION['name'] seems to have completely vanished.
Anyone know why this is happening? I can be a little more specific if neccessary.
Thanks.
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
use the above to every page you initialize sessions to check what is being passed/defined/set/unset
Try the code in both header and footer of your pages.
Is it pssible that between page 2 and page 3 you do some other redirection, through a page that do not have session_start()?
On page 3 you said that $_SESSION['name'] do not work. What about $_SESSION['lname']? Does it has any value?
$expireTime = 60*60*24*1; // 1 day
$sessdir = "/path/";
//session_save_path($sessdir);
//session_set_cookie_params($expireTime);
session_start();