Forum Moderators: coopster

Message Too Old, No Replies

Trouble with $ SESSION migrating from PHP 4.3.9 to 5.1.4

$_SESSION is being reset on page load

         

formasfunction

12:32 am on Oct 29, 2007 (gmt 0)

10+ Year Member



I'm moving my first code over from a PHP 4.3.9 system running as an apache module to 5.1.4 running as CGI and my $_SESSION variable isn't retaining any of my values from page to page. With the php5 install if I put

++$_SESSION['test'];
print_r($_SESSION);

It keeps printing the number 1 when I refresh the page whereas with my PHP 4 install it gradually counts upward.
I'm hoping this is something small with the configuration of PHP 5. The first thing I checked was register_globals which is off in both systems.

formasfunction

3:29 am on Oct 29, 2007 (gmt 0)

10+ Year Member



Here's a better example. I've boiled it down to one test page with the following code:


<?php
if (session_id() == ""){
session_start();
}
++$_SESSION['test'];
print(session_id());
print_r($_SESSION);
?>

In PHP 4.3.9 the session_id stays the same from page load to page load and the array item "test" increments by one each time. With PHP 5.1.4 the session_id stays the same as well but "test" doesn't increment at all but rather stays at 1. I've tested this in both Firefox and Safari.

Any ideas? It's like it isn't retaining the value. I ran the same script above on my laptop with Apache and PHP 5.2.1 and it worked just fine, incrementing as it should.

formasfunction

8:58 am on Oct 29, 2007 (gmt 0)

10+ Year Member



I just checked out the session folder on my server that should be holding all of the session files for php 5 and there's nothing in there so perhaps php 5 isn't writing to it. Is there a way to confirm that? It appears that it has the same permissions as the php 4 install on the same server. Maybe since it's running as CGI it should be configured differently? Help!

formasfunction

9:56 pm on Oct 29, 2007 (gmt 0)

10+ Year Member



I found the problem - for some reason my host hadn't set the permissions correctly for the folder php was trying to write the sessions file to. Fixed.