Session variables in an include

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
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Session variables in an include

Post by Citizen »

Basically, I have set $_SESSION['loggedin'] and its coming up fine in my root level pages but wont show up in my included pages.

So...

index.php echos $_SESSION['loggedin'] fine
- top.php includes leftbar.php
-- leftbar does not echo $_SESSION['loggedin']

any ideas?
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

could you please post the code you are running?

Wayne
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Session variables in an include

Post by volka »

Citizen wrote:index.php echos $_SESSION['loggedin'] fine
- top.php includes leftbar.php
index.php includes top.php?
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

Found the problem!

I was using an absolute path to include the leftbar.php instead of using a relative path. The page previously included fine but the session variables weren't working becuase of the absolute path.

Thanks though!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If you were developing with display errors on you probably would have seen a notice that the file could not be included. Just a tip for future development.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Citizen wrote:The page previously included fine but the session variables weren't working becuase of the absolute path.
By "absolute path" you mean "sobsolute uri" like http://serv.er/xyz/left.php?
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

volka wrote:
Citizen wrote:The page previously included fine but the session variables weren't working becuase of the absolute path.
By "absolute path" you mean "sobsolute uri" like http://serv.er/xyz/left.php?
Right.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

8O :oops: [s]sobsolute[/s] -> absolute
Post Reply