Page 1 of 1

Odd Session Weirdness with the include Statement

Posted: Mon Jan 04, 2010 3:00 pm
by Bigun
I'm trying to code a site, that carries a set of session variables.

So I create a header php file with the session_start() command in it:

header.php

Code: Select all

 
session_start();
 
So then I include this file in my other two php files, index.php and dashboard.php. I can set session variables in index.php, and doing a print_r($_SESSION) gives the expected output. However, when I go to dashboard.php, only one of the $_SESSION variables carries.

I then double back and take the session_start statement out of the header and put it into the tops of both the index.php and dashboard.php, and it works fine.

Are there any known issues with putting a session_start statement in a header file?

Re: Odd Session Weirdness with the include Statement

Posted: Mon Jan 04, 2010 3:23 pm
by jason
To answer your question: no.

You should, however, post 'index.php', 'dashboard.php', and 'header.php', as I'm sure the problem is simply, but lies in there.

Re: Odd Session Weirdness with the include Statement

Posted: Mon Jan 04, 2010 6:37 pm
by manohoo
"Before you can begin storing user information in your PHP session, you must first start the session. When you start a session, it must be at the very beginning of your code, before any HTML or text is sent."

http://www.tizag.com/phpT/phpsessions.php

Re: Odd Session Weirdness with the include Statement

Posted: Tue Jan 05, 2010 11:49 am
by Bigun
Scratch all of that.... I had the header included in the wrong spot....

:banghead: