954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem with sessions

Hello all,

I've been having an issue with php variables recently. I don't have much experience working with sessions, but I know that domain.com and www.domain.com are viewed differently when working with sessions. The problem I have is with included files. I am calling .../logbook/header.php from ...logbook/Graphs/index.php. When I use include_once('header.php') from files within logbook/, I am able to use the session variables, but when I include the full path in the include_once() command, I can't access the session. How can I set the session so that it is accessible to both 'header.php' and '.../full path/header.php'?

grant.baker
Newbie Poster
23 posts since Aug 2010
Reputation Points: 20
Solved Threads: 1
 

ensure the full path is correct

vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 
ensure the full path is correct


Do you mean in the include_once() command or when I set the session? It's correct in the include command, and I don't know how to set it explicitly when I set sessions.

grant.baker
Newbie Poster
23 posts since Aug 2010
Reputation Points: 20
Solved Threads: 1
 
session_start();

// set session
$_SESSION['your_session_name'] = "your_value";

// read session
$_SESSION['your_session_name'];
vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 

No, my session is set. I can echo my session id in the logbook/Graphs/index.php page, but not from header.php when it's included from logbook/Graphs/index.php.

grant.baker
Newbie Poster
23 posts since Aug 2010
Reputation Points: 20
Solved Threads: 1
 

well that's weird, maybe you haven't included the header.php correctly in the index.php, because if you include it right the header.php becomes part of the index.php, try echoing or alerting text in header.php, to test if is really included

vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 

I know it's odd. It's most definitely included. It's my header file with my navigation menu. I include it on every page. If I include

session_start();echo session_id();


in header.php it echoes the same session id on all the pages except when it's included from a file located in a subfolder.

grant.baker
Newbie Poster
23 posts since Aug 2010
Reputation Points: 20
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: