1

I need help with PHP session variables. I am registering them, and then they print fine from the same page, but other pages are not getting them correctly.

Here is the page that is setting them

if($logIn){
    session_start();
    $_SESSION['name'] = $username;
    $_SESSION['pass'] = $check[1];
    $_SESSION['email'] = $email;
    $_SESSION['addr'] = $check[3];
    echo $_SESSION['name']." is ";
    echo "logged in";
} else {
    echo "nogo";
}
fclose($fp);

and then the page linked to has

<body>
<?php include '../header.php'; ?>
<?php echo $_SESSION['name']."lets go"; ?>

And it will not print anything...can't figure this out.

Thanks in advance!

1
  • Are they 2 separate files? If they are, in the second file you have to make sure to call session_start() again Commented Mar 7, 2014 at 2:30

1 Answer 1

8

session_start(); start must got at the top of every page before any output. Make sure on the second page you have that at the top of the page or else you will get no output from session variables.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.