Page 1 of 1

Why does $_SESSION['count'] = $count?

Posted: Wed Sep 25, 2002 10:45 am
by finale
I'm forced into using version 4.1.2. Something to do with the new Apache not liking some kind of SSL or something.

Anyway, I've narrowed down a problem to a bit of sample code below. The system is thinking that $_SESSION['count'] and $count are the same variable. The sample code is the entire code file I am running and getting this peculiarity.

I don't understand. I thought $SESSION was an entirely separate array variable isolated from other variables but when I execute this code the two variables keep incrementing together except the first time when one is 0 and one is undefined.

This did not happen on another server I was using a few months ago.

Is this a setting in php.ini or can anyone help explain

session_name("Test");
session_start();
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
} else {
$_SESSION['count']++;
}
echo($_SESSION['count']);
echo($count);

Posted: Wed Sep 25, 2002 10:53 am
by volka
from http://www.php.net/manual/en/ref.session.php:
If both track_vars and register_globals are enabled, then the globals variables and the $HTTP_SESSION_VARS/$_SESSION entries will reference the same value for already registered variables.

Posted: Wed Sep 25, 2002 11:07 am
by finale
Thanks. I did read that section but somehow this part was not clear to me.