SESSION puzzle

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I've been researching this for a while now -- perhaps someone here
knows the explanation.

I uploaded to my remote host (system info: PHP Version 4.3.11, FreeBSD 5.3-RELEASE-p13 FreeBSD 5.3-RELEASE-p13 #0: i386) a
script that uses $_SESSION variables to control output between page
loads.  (I've pasted what I think is the relevant code at the end of
the message.)

What I want the script to do: create an html string (a panel) that
contains some random data (an ID) that will be saved to the session.
Thus, if the page is reloaded, the same panel with the same ID will be
displayed.  A user can modify the panel using an input field, which
will then be saved to session and redisplayed upon reload.  There's
also a button to get a completely new panel.  On my local WAMP
installation (system info: PHP Version 5.0.3, Windows NT build 2600),
everything works fine and SESSION data gets saved.  This has worked on
2 different but similar local WAMP servers.  See simplified code at

The problem: On the remote server, SESSION data does not get saved.
I've never had this problem with any other scripts I've run on this
host.  The only anomalies in this script that I can think of:

1. include path gets changed so I can use my own locally cobbled config
of PEAR without conflicts (Script does not require PEAR, however, and I
reran it without it but this did not solve problem)

2. session variable is getting saved within a function (not in main
scope of script)

Like I said, no problem on my local server, but won't work on the
remote host.  I've echoed the $_SESSION variables and confirmed that
the variables are not being saved between page reloads.

I just checked with my host and they set up a simple page for me that
demonstrated that sessions are operating

Probably something silly and obvious but I can't figure it out for the
life of me.  And the fact that it works in one environment and not the
other has me utterly baffled and make me think it's something exotic,
beyond my reckoning.  Any help you can offer will be appreciated.



Essential Code:

if ( !session_id() ) { session_start(); }

# POST : get_new_panel
if ( $_POST['get_new_panel'] )
 $_SESSION['panel'] = '';
 $_SESSION['form_input']['valid']['name'] = '';

# new panel
if ( empty($_SESSION['panel']) )
 $HTML['panel'] = cx_panel();

# add user input to panel
elseif ( !empty($_SESSION['form_input']['valid']['name']) )
 $HTML['panel'] = cx_panel($_SESSION['form_input']['valid']['name'],

# existing panel
 $HTML['panel'] = $_SESSION['panel'];

echo $HTML['panel'];

note: the cx_panel function both returns html string and saves it to

Re: SESSION puzzle

In response to my own question, I finally discovered this:

fondman at hotmail dot com
06-Dec-2005 02:47

I just solve a problem about $_SESSION variable.
For example, you set $_SESSION['username'] = "Michael" already, later,
you have a variable $username = "Chi" in a php script
After PHP 4.4.0, $_SESSION['username'] is still "Michael".
However, In PHP 4.3.*,  $_SESSION['username'] is also changed to "Chi".

Be Careful, if the php version is lower than 4.4.0!

My problem was a variation on this theme.  It does pose a bit of
problem for the framework I put together.  Glad to hear it's been fix
in PHP 4.4+.

Site Timeline