tags:

views:

173

answers:

4

Hi All,

I have a problem where i am losing the PHP session between 2 pages.

The session_start() is included in a file called session-inc.php into every page requiring a session to be set. This works for all pages on the site except one particular page, member-profile.php. When this page is visited a new session with a different id (same session name) is set and used instead.

A few more details:

  • Session name is set manually
  • All pages are on the same server under the same domain name
  • If i put an additional session_start() above the include('session-inc.php') in the member-profile.php file, the session is carried over correctly
  • I have tried setting the session_cookie_domain and session.session_name in the .htaccess, this worked for this domain but it stopped the session being passed over to out payment domain
  • We are running apache 2.2.6 with php 5.2.5

Putting the session_start() above the include('session-inc.php') in the member-profile.php file is the quick and dirty fix for this problem, but i am wondering if anybody know why this would be happening.

Cheers

Will

A: 

According to PHP documentation, session_start must be called before any output is sent back to the browser-- could this page have a rogue CR/LF, Unicode byte-order mark or similar that is causing output before you include('session-inc.php')?

Ken Keenan
Hi KenI have checked the scripts and there doesnt seem to be any output before the session_start() call.
willl69
A: 

Found the issue

There was a byte order mark at the beginning of the main includes file of the second domain. as stated by ken, cant have any output before a session start, it was not setting the session correctly.

willl69
A: 

While migrating a legacy site from PHP4 to PHP5 I noticed a php.ini configuration setting that causes php to auto-start the session upon every request. It's an alternative to placing session_start() onto every page...

There are multiple ways to enable this setting:

Put the following line into php.ini:

session.auto_start = on

or put this into your apache virtual-site config or .htaccess file:

<IfModule mod_php5.c>
  php_flag session.auto_start on
</IfModule>

and it should make $_SESSION changes available across all pages

Henrik Eiriksson
A: 

Found the problem was a byte order mark (BOM) being ouputted at the start of the file. Got rid of it and it sorted out the session problem.

willl69

related questions