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

PHP5 and Global Array ($_GET)

P: n/a
gf
I had a client recently contact me with a script that wasn't working. I
quickly isolated the problem as to the fact that the $_GET array was not
being made available to all scripts, even though register_globals was set to
ON. The client then notified his host who seemed to know exactly the issue
and we added these lines to the top of the script (this script is included
in all other scripts) and it solved the problems:

/* mp.net patch */
foreach($_GET as $var => $value) $$var = $value;
foreach($_POST as $var => $value) $$var = $value;
foreach($_COOKIE as $var => $value) $$var = $value;
foreach($_SERVER as $var => $value) $$var = $value;
ob_start();
/* end of patch */

The host added these comments to my client:
"I can fix that for you, but in a couple of months, PHP5 will be out for
real, so you might as well want to fix it in your code."

Is this a work-around for right now or is there some kind of rework that all
scripts will have to be modified for version 5?

--
Gaylen
Raven Web Hosting http://ravenwebhosting.com
PHP KISGB PHP Guest Book for Standard and phpNuke sites
http://www.ravenphpscripts.com
PHP KISSQ PHP Stock Quote for Standard and phpNuke sites
http://www.ravenphpscripts.com
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
gf:
I had a client recently contact me with a script that wasn't working. I
quickly isolated the problem as to the fact that the $_GET array was not
being made available to all scripts, even though register_globals was set
to
ON. The client then notified his host who seemed to know exactly the
issue and we added these lines to the top of the script (this script is
included in all other scripts) and it solved the problems:

/* mp.net patch */
foreach($_GET as $var => $value) $$var = $value;
foreach($_POST as $var => $value) $$var = $value;
foreach($_COOKIE as $var => $value) $$var = $value;
foreach($_SERVER as $var => $value) $$var = $value;
ob_start();
/* end of patch */
// A simpler solution:
extract($_REQUEST);
extract($_SESSION);
The host added these comments to my client:
"I can fix that for you, but in a couple of months, PHP5 will be out for
real, so you might as well want to fix it in your code."

Is this a work-around for right now or is there some kind of rework that
all scripts will have to be modified for version 5?


register_globals is considered a bad thing, so you should really strive to
move away from it.

André Nęss
Jul 17 '05 #2

P: n/a
gf
"André Nęss" <an*********************@ifi.uio.no> wrote in message
news:bn**********@maud.ifi.uio.no...
gf:
I had a client recently contact me with a script that wasn't working. I
quickly isolated the problem as to the fact that the $_GET array was not
being made available to all scripts, even though register_globals was set to
ON. The client then notified his host who seemed to know exactly the
issue and we added these lines to the top of the script (this script is
included in all other scripts) and it solved the problems:

/* mp.net patch */
foreach($_GET as $var => $value) $$var = $value;
foreach($_POST as $var => $value) $$var = $value;
foreach($_COOKIE as $var => $value) $$var = $value;
foreach($_SERVER as $var => $value) $$var = $value;
ob_start();
/* end of patch */


// A simpler solution:
extract($_REQUEST);
extract($_SESSION);
The host added these comments to my client:
"I can fix that for you, but in a couple of months, PHP5 will be out for
real, so you might as well want to fix it in your code."

Is this a work-around for right now or is there some kind of rework that
all scripts will have to be modified for version 5?


register_globals is considered a bad thing, so you should really strive to
move away from it.

André Nęss

That's not the point, though, although I understand. This is not my
application and the application requires it.

Can anyone address my original question?

Gaylen
Raven Web Hosting http://ravenwebhosting.com
PHP KISGB PHP Guest Book for Standard and phpNuke sites
http://www.ravenphpscripts.com
PHP KISSQ PHP Stock Quote for Standard and phpNuke sites
http://www.ravenphpscripts.com
Jul 17 '05 #3

P: n/a
gf wrote:
I had a client recently contact me with a script that wasn't working. I
quickly isolated the problem as to the fact that the $_GET array was not
being made available to all scripts, even though register_globals was
set
to
ON.

Though I am not sure about PHP5 it might be different but perhaps if
there were no query string parameters passed like script.php?foo=bar
then PHP has no need to create and populate a $_GET array. This might be
a bug where when you include() other files it doesn't see it as the same
request and carry over the super globals. I don't know I have yet to sit
down and hammer out code for PHP5 given its still beta. Also I always
use isset() on a variable if its supplied in _GET/_POST/_COOKIE to make
sure that its actually there. And again tell your client to stop
requiring register_globals or they might find themselves left in the
dust, PHP is still a young language and continues to evolve.

--
John Downey
http://delusive.dyn.ee
http://sage.dev.box.sk
http://blacksun.box.sk

Jul 17 '05 #4

P: n/a
gf:
register_globals is considered a bad thing, so you should really strive
to move away from it.
That's not the point, though, although I understand. This is not my
application and the application requires it.

Can anyone address my original question?


Ok, I guess what you're wondering is "Will register globals disappear from
PHP5?". The answer seems to be no, see: http://zend.com/php/ask_experts.php
(currently fifth question from top).

André Nęss
Jul 17 '05 #5

P: n/a
gf
"John Downey" <bl**@doesntexist.com> wrote in message
news:%t***********************@twister.neo.rr.com. ..
gf wrote:
I had a client recently contact me with a script that wasn't working. Iquickly isolated the problem as to the fact that the $_GET array was notbeing made available to all scripts, even though register_globals was


set
to
ON.

Though I am not sure about PHP5 it might be different but perhaps if
there were no query string parameters passed like script.php?foo=bar
then PHP has no need to create and populate a $_GET array. This might be
a bug where when you include() other files it doesn't see it as the same
request and carry over the super globals. I don't know I have yet to sit
down and hammer out code for PHP5 given its still beta. Also I always
use isset() on a variable if its supplied in _GET/_POST/_COOKIE to make
sure that its actually there. And again tell your client to stop
requiring register_globals or they might find themselves left in the
dust, PHP is still a young language and continues to evolve.

--
John Downey
http://delusive.dyn.ee
http://sage.dev.box.sk
http://blacksun.box.sk

They are being passed. This works perfectly on v4.x . There are no issues
with the way the script is apssing anything. it is directly related to
something in php5.

--
Gaylen
Raven Web Hosting http://ravenwebhosting.com
PHP KISGB PHP Guest Book for Standard and phpNuke sites
http://www.ravenphpscripts.com
PHP KISSQ PHP Stock Quote for Standard and phpNuke sites
http://www.ravenphpscripts.com
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.