Odd Session Weirdness with the include Statement

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
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Odd Session Weirdness with the include Statement

Post 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?
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Re: Odd Session Weirdness with the include Statement

Post 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.
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: Odd Session Weirdness with the include Statement

Post 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
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Re: Odd Session Weirdness with the include Statement

Post by Bigun »

Scratch all of that.... I had the header included in the wrong spot....

:banghead:
Post Reply