Click to See Complete Forum and Search --> : variable frustration


rutledj
12-13-2005, 07:01 PM
Forgive me asking such simple questions but I'm a bit confused.
On my index.php page I have this:

<?php
session_start();
$_SESSION['isadmin'] = 'NO';
?>

On a member login page I have this:

<?php
$flag = $_SESSION['isadmin'];
if ($flag == 'YES'){
echo $flag;
}
?>

When I run it I get:

PHP Notice: Undefined variable: _SESSION in c:\Inetpub\wwwroot\memberlogin.php on line 67

Can someone explain why it is flagging _SESSION as an undefined variable?

Thanks,
Rut

NogDog
12-13-2005, 07:11 PM
You need a session_start() on any page that is going to interact with the $_SESSION array.

rutledj
12-13-2005, 07:23 PM
So you have to put it on every page? I thought it was a one time thing!

NogDog
12-13-2005, 08:09 PM
Yeah, the name sort of sounds like it's just used to "start" the session, but it means to start session processing for the currently running script.

Sheldon
12-13-2005, 09:04 PM
and dont forget that it needs to be at the top of the page with no gaps before the <?php part.