Page 1 of 1
$_SESSION not seen by included file...
Posted: Thu May 05, 2005 5:38 pm
by 99miles
I have a page with:
include( $_SESSION['site_root'] . "includes/header.php" );
that file is included just fine, so $_SESSION['site_root'] is fine at this point.
but inside header.php I have:
echo $_SESSION['site_root'];
and I get the message:
PHP Notice: Undefined index: site_root in (file path)...
What's going on here? Thanks!
Posted: Thu May 05, 2005 6:12 pm
by PrObLeM
did you do session_start(); on the top of header.php?
Posted: Thu May 05, 2005 6:22 pm
by 99miles
yup.
Posted: Thu May 05, 2005 9:47 pm
by John Cartwright
sounds like you have not initialized your session variable before using it.
Show us the rest of the source.
Posted: Fri May 06, 2005 1:00 am
by 99miles
It is initialized correctly, otherwise the file I'm including wouldn't be found. I'm using the exact same session variable to specify the path to the file I'm including as I am within that included file.
Hmm...
Posted: Fri May 06, 2005 1:06 am
by 99miles
But, here's a sample...
index.php ->
Code: Select all
<?
session_start();
$_SESSIONї'path'] = "e;http://localhost/temp/"e;;
echo "e;PATH: "e; . $_SESSIONї'path'] . "e;<br/>"e;;
include( $_SESSIONї'path'] . "e;inc.php"e; );
?>
inc.php ->
Code: Select all
<?
session_start();
echo "e;PATH: "e; . $_SESSIONї'path'];
?>
Posted: Fri May 06, 2005 5:59 am
by timvw
99miles wrote:It is initialized correctly, otherwise the file I'm including wouldn't be found. I'm using the exact same session variable to specify the path to the file I'm including as I am within that included file.
You are mistaken/tricked by PHP here. It all depends on how your include_path looks like.
Posted: Fri May 06, 2005 12:34 pm
by 99miles
in my .ini file? I'm not sure what that has to do with this script? I'm providing the full path to the file, and the file IS being included, but the $_SESSION is not found by the included file...
Am I misunderstanding you?
Posted: Fri May 06, 2005 12:40 pm
by shiznatix
the file is being included but $_SESSION is not being found by the included file??
have you tried print_r($_SESSION); on the included page to see if the session array is there?