$_SESSION not seen by included file...

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
99miles
Forum Newbie
Posts: 8
Joined: Thu May 05, 2005 5:35 pm

$_SESSION not seen by included file...

Post 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!
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

did you do session_start(); on the top of header.php?
99miles
Forum Newbie
Posts: 8
Joined: Thu May 05, 2005 5:35 pm

Post by 99miles »

yup.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

sounds like you have not initialized your session variable before using it.
Show us the rest of the source.
99miles
Forum Newbie
Posts: 8
Joined: Thu May 05, 2005 5:35 pm

Post 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...
99miles
Forum Newbie
Posts: 8
Joined: Thu May 05, 2005 5:35 pm

Post by 99miles »

But, here's a sample...
index.php ->

Code: Select all

<?
session_start();

$_SESSION&#1111;'path'] = &quote;http://localhost/temp/&quote;;

echo &quote;PATH: &quote; . $_SESSION&#1111;'path'] . &quote;<br/>&quote;;

include( $_SESSION&#1111;'path'] . &quote;inc.php&quote; );
?>
inc.php ->

Code: Select all

<?
session_start();

echo &quote;PATH: &quote; . $_SESSION&#1111;'path'];

?>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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.
99miles
Forum Newbie
Posts: 8
Joined: Thu May 05, 2005 5:35 pm

Post 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?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

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