By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,747 Members | 2,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,747 IT Pros & Developers. It's quick & easy.

register_globals, effects on $_GET and $_SESSION

P: n/a
I read php manual many times but I can't figure out register_globals
works. I m using Php 4.3.2 and register_globals on. It seems to have
different effects on $_GET and $_SESSION. First with $_GET :

<? echo $var."\n";
echo $_GET['var']."\n";
$var="gna";
echo $var."\n";
echo $_GET['var']."\n";
$_GET['var']="gnou";
echo $var."\n";
echo $_GET['var']."\n";
?>

This page is called by <a href="work3.php?var=gni">work3</a>.
And produce this output :
gni
gni
gna
gni
gna
gnou
What I understand is that before reading the script, a global variable
is created with the same name and value as _GET['var'] but these are
eventually two distinct variables.

Then with $_SESSION :
<? session_start();
$_SESSION['test3'] = 'this is a test3';
?>
<a href="work5.php">work5</a>

and in work5.php
<? session_start();
echo $test3."\n";
echo $_SESSION['test3']."\n";
$test3="gna";
echo $test3."\n";
echo $_SESSION['test3']."\n";
$_SESSION['test3']="gnou";
echo $test3."\n";
echo $_SESSION['test3']."\n";?>

This produce :
this is a test3
this is a test3
gna
gna
gnou
gnou
What I understand here is that before reading the script, a global
variable is created with the same name and value as _SESSION['test3']
but they share the same memory.

Where does it comes from ? Is it an extra work from session_start() ?

Jul 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.