Jump to content

SuperGlobal / register_globals


steadythecourse

Recommended Posts

Hello All!

Can anyone explain why when I run the following code

 

<?php
print_r($GLOBALS);
?> 

 

I get the following output

 

Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( ) [_COOKIE] => Array ( ) [_FILES] => Array ( ) )

 

 

which is expected since register_globals is set to off and no variables are defined, but when I add the following code. which is just to echo out a variable from the superglobal $_SERVER, the print_r($GLOBALS) now outputs all the superglobal $_SERVER variables as if echo somehow made all the variables available to the script and now $GLOBALS sees them. maybe a stupid question I don't know. For obvious reasons I can't show the output, but it's easy enough to run the code to view your systems output.

 

<?php
print_r($GLOBALS);
echo "<br />";
echo "<br />";
echo $_SERVER["DOCUMENT_ROOT"];
?> 

 

Thanks,

steadythecourse

Link to comment
Share on other sites

if they are of then they will remain blank or should

 

print_r on any of the individual things $_POST, $_GET, $_Cookie, etc.. would output similar but within its own particular element. In other word's print_r($GLOBAL) is the same as print_r($COOKIE) or print_r($SESSION) only difference is $GLOBAL will look them all up.

 

also now in hien site of my typing.. global variables off.... thats a whole different thing. Global variables are variables that you can call $tacomeat for example.. and call it any which way you want, $_POST, $_GET, other... doesnt matter what sets it, as long as its set, where with that off, I can't go to your site and much around with setting my own sessions, cookies, or other variables through means unknown.. and trip up your script cause of it.

 

its always good practice in my opinion to stick with ensuring your variables are coming from where you want them to come from, ie $_POST, $_GET, other..

 

hopefully this all helps out some, I'm tired, I am just waking up, coffee hasn't hit me yet.

Link to comment
Share on other sites

Or for the actual answer to your question -

; When enabled, the SERVER and ENV variables are created when they're first

; used (Just In Time) instead of when the script starts. If these variables

; are not used within a script, having this directive on will result in a

; performance gain. The PHP directives register_globals, register_long_arrays,

; and register_argc_argv must be disabled for this directive to have any affect.

; http://php.net/auto-globals-jit

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.