Page 1 of 1

I need beginner's code help

Posted: Mon Dec 08, 2003 5:23 am
by dbudde
OK, I seem to be having a problem where my session variables are not registering properly. They seem to exist only for the existance of the page they are referenced on and that is it.
My code for page 1 and 2 follow respectively.

PAGE1
<?php
session_start();
$_SESSION['logged_in'] = "False";
?>

PAGE2
<?php
if (!isset($_SESSION['logged_in'])) {
header("Location: http://returntopage1");
/* Redirect browser */

/* Make sure code below does not execute when we redirect. */
exit;
}
?>

The page 2 is never displayed, it always goes back to page 1, so therefore I do not believe logged_in variable is ever making it to page 2.

Any help would be greatly appreciated.

Posted: Mon Dec 08, 2003 5:52 am
by twigletmac
You need to have session_start() in page2 as well as in page1 (in fact on any page in which you want to use sessions).

Mac

Ok, i tried that

Posted: Mon Dec 08, 2003 11:57 am
by dbudde
I added the session_start(); to the second page, but it is still not recognizing that $_SESSION['logged_in'] has been created and it still just redirects back to the first page. Any more suggestions would be appreciated.