Page 1 of 1

Session variables problem

Posted: Wed Jul 14, 2010 8:21 am
by ulezacvenje
Hello!

I've noticed this strange PHP behavior. Following example shows that these two variables, $_SESSION['name'] and $name are actually single variable. When one of them is given some value, the other takes this same value?!

Code: Select all

session_start();
if (!session_is_registered('name')) session_register('name');
echo 'before:' . $_SESSION['name'];
$name = 'value 1';
echo '<br>after:' . $_SESSION['name']; // this should echo only 'after:' but it echoes 'after:value 1'
$_SESSION['name'] = 'value 2';
echo '<br>finally:' . $name; // this should echo 'finally:value 1' but it echoes 'finally:value 2'
This strange behavior had caused me many headaches in the past, until I have noticed it. I tried to google it but I don't know if PHP should behave like that or not?

Thank you!

Re: Session variables problem

Posted: Thu Jul 22, 2010 9:59 am
by Ragnis
From your php.ini file set register_globals = Off

Re: Session variables problem

Posted: Tue Jul 27, 2010 4:07 am
by ulezacvenje
Thank you, Ragnis. But before I send register_globals = Off request to my site's host, I'd like to know whether variables from my included PHP scripts will be visible from the main PHP file and vice versa?

Re: Session variables problem

Posted: Fri Jul 30, 2010 4:56 am
by anilnakkani
As per security issue register_globals should be off, other all our POST,GET,and COOKIE data is visable for all.
Always register_globals = off; in php.ini file

Thanks
Anil.N
Thought Radius - Experts for Partners