I need beginner's code help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dbudde
Forum Commoner
Posts: 25
Joined: Mon Dec 01, 2003 4:02 pm
Location: Chicago, IL

I need beginner's code help

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
dbudde
Forum Commoner
Posts: 25
Joined: Mon Dec 01, 2003 4:02 pm
Location: Chicago, IL

Ok, i tried that

Post 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.
Post Reply