steadythecourse Posted October 10, 2010 Share Posted October 10, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/215539-superglobal-register_globals/ Share on other sites More sharing options...
monkeytooth Posted October 10, 2010 Share Posted October 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/215539-superglobal-register_globals/#findComment-1120827 Share on other sites More sharing options...
PFMaBiSmAd Posted October 10, 2010 Share Posted October 10, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/215539-superglobal-register_globals/#findComment-1120828 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.