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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
finale
Forum Newbie
Posts: 4
Joined: Tue Jul 16, 2002 11:35 am

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

Post 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);
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
finale
Forum Newbie
Posts: 4
Joined: Tue Jul 16, 2002 11:35 am

Post by finale »

Thanks. I did read that section but somehow this part was not clear to me.
Last edited by finale on Wed Sep 25, 2002 11:12 am, edited 1 time in total.
Post Reply