$_SESSION not seen by included file...
Moderator: General Moderators
$_SESSION not seen by included file...
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!
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!
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
But, here's a sample...
index.php ->
inc.php ->
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; );
?>Code: Select all
<?
session_start();
echo "e;PATH: "e; . $_SESSIONї'path'];
?>You are mistaken/tricked by PHP here. It all depends on how your include_path looks like.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.