[Techtalk] Weird PHP session variable problem

Vera Childs vera at dc-vc.net
Wed Feb 12 10:07:12 EST 2003


I'm doing some enhancements for an existing website. The website involves
registering users, and currently they have the option to change their
password. I've been tasked to allow them to also change their e-mail
address. This should be really easy to do, and I thought it was until I ran
into a show-stopper problem.

I essentially took the password changing functions and changed them
appropriately to update e-mail instead of password. When I went to try it
out, it wasn't working. So I tracked down what exactly wasn't working, and
it turns out to be that a session variable is not staying with the session.
I double checked how I was setting that variable, and it was done exactly
the same as the password variable was done. The password works. The e-mail
doesn't.

Here's the appropriate code for the password functions:

-----
function1:

session_register('GLOBAL_OBJECTS');
$GLOBAL_OBJECTS['chpass']['step'] = 1;

function2:

if
((isset($GLOBAL_OBJECTS['chpass']['step']))and($GLOBAL_OBJECTS['chpass']['st
ep']==1)) {
  // Do stuff
  // Eventually set step to 2 same way as done in function 1
}
-----

The above works. Now here's the weird thing... If I change 'chpass' in the
above to 'chemail' (in all places, so that the password function is just
using a different variable name, but still doing all the same things), it
doesn't work! Change it back to 'chpass' and it works. I'm stumped!

I've rebooted the server (my desktop, used for development), but I still
get the same results. I think it is a problem with the server (Mandrake
Linux 9.0 with Apache 1.3.26 and PHP 4.2.3 installed from MDK rpms). I just
don't know where to begin in resolving this issue.

Things I've tried:
1) using session_is_registered instead of isset function
2) using $_SESSION variable instead of registering $GLOBAL_OBJECTS
3) adding another $GLOBAL_OBJECTS variable (eg $GLOBAL_OBJECTS['bob']) to
be set right after the chpass step is set. The chpass step stays with the
session. The bob does not.
4) using different users of the site
5) using different computers to access the site
6) rebooting server and computers connecting to the site
7) undoing all changes (cvs update -C) and doing them again.
8) undoing all changes and just changing 'chpass' to 'chemail'.

Any ideas? This just doesn't make sense to me. If I check the session
registration of the variable right after setting it, that works. It just
doesn't exist in the following function. This step business is used in
several sections of the code, and works in every instance. I just can't
change anything about those variables and get them to work. Nor can I add a
new session variable.


-Vera






More information about the Techtalk mailing list