Forum Moderators: coopster

Message Too Old, No Replies

php autoglobals

         

outlaw

9:13 pm on Feb 19, 2006 (gmt 0)

10+ Year Member



Quick question:
I know that PHP 4.1+ registers certain things as autoglobals such as POST, COOKIE, SERVER...etc.

I also noticed that:
$foo==$_POST['foo']
and
PHP_SELF==$_SERVER['PHP_SELF']

Global means that the var is available throughout the scope of the php, but I never read anything about this shorthand. With careful scripting and using distingushed vars, is it otherwise safe to call the requested variable directly?

DrDoc

9:19 pm on Feb 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Register globals can be dangerous. Very dangerous.

What happens, for example, if you are expecting a certain variable to be sent using POST, and someone sends it in the query string?

Also, relying on these global variables ... they can reset variables if you don't code carefully.

As of later versions of PHP, register globals is turned off by default.

For further information about what register globals is, and why it may be "dangerous": [php.net...]