Superian Posted August 10, 2008 Share Posted August 10, 2008 Could someone please give me an idea about how to check the following script to see if its working properly? Thanks! <?php function unset_register_globals() { if (ini_get('register_globals')) { foreach ($GLOBALS as $key => $value) { if (!in_array($key, array('_ENV' => 1, '_GET' => 1, '_POST' => 1, '_COOKIE' => 1, '_FILES' => 1, '_SERVER' => 1, '_REQUEST' => 1, 'GLOBALS' => 1))) { unset($GLOBALS[$key]); } } } } ?> Quote Link to comment Share on other sites More sharing options...
deadlyp99 Posted August 10, 2008 Share Posted August 10, 2008 Test it. If you see nothing, create some checks that will verify the data the code is looking for has been found, or has not. You can use a counter on the foreach to print which "revolution" of the loop it is on when and if it unsets $Globals. Adding $x = 1; after the first if statement, and: x++;echo $x; after unset $globals should do the trick. Good luck. And you could always simply add: echo $Globals[$key]; inside the second if statement. Quote Link to comment Share on other sites More sharing options...
Superian Posted August 10, 2008 Author Share Posted August 10, 2008 Test it. If you see nothing, create some checks that will verify the data the code is looking for has been found, or has not. You can use a counter on the foreach to print which "revolution" of the loop it is on when and if it unsets $Globals. Adding $x = 1; after the first if statement, and: x++;echo $x; after unset $globals should do the trick. Good luck. And you could always simply add: echo $Globals[$key]; inside the second if statement. I am getting no output! Quote Link to comment Share on other sites More sharing options...
deadlyp99 Posted August 10, 2008 Share Posted August 10, 2008 ok ad d this to the if statement: if (all the junnk){ Quote Link to comment Share on other sites More sharing options...
deadlyp99 Posted August 10, 2008 Share Posted August 10, 2008 Woops, ignore that. Just add an else statement to the if. }else { echo "IF was false!\n" } Quote Link to comment Share on other sites More sharing options...
Superian Posted August 10, 2008 Author Share Posted August 10, 2008 Woops, ignore that. Just add an else statement to the if. }else { echo "IF was false!\n" } I'm sorry, but I am lost buddy. Getting an error! <?php function unset_register_globals() { if (ini_get('register_globals')) { foreach ($GLOBALS as $key => $value) { if (!in_array($key, array('_ENV' => 1, '_GET' => 1, '_POST' => 1, '_COOKIE' => 1, '_FILES' => 1, '_SERVER' => 1, '_REQUEST' => 1, 'GLOBALS' => 1))) { unset($GLOBALS[$key]); } else ($GLOBALS[$key] == false) { print "Unset"; } } } } unset_register_globals(); ?> Quote Link to comment Share on other sites More sharing options...
deadlyp99 Posted August 10, 2008 Share Posted August 10, 2008 That is because your syntax is wrong. In php, the else statment takes no arguements, that is what the else if statment is for, but for this purpose just change that part to: <?php function unset_register_globals() { if (ini_get('register_globals')) { foreach ($GLOBALS as $key => $value) { if (!in_array($key, array('_ENV' => 1, '_GET' => 1, '_POST' => 1, '_COOKIE' => 1, '_FILES' => 1, '_SERVER' => 1, '_REQUEST' => 1, 'GLOBALS' => 1))) { unset($GLOBALS[$key]); } else { print "Unset"; } } } } unset_register_globals(); ?> Quote Link to comment Share on other sites More sharing options...
Superian Posted August 10, 2008 Author Share Posted August 10, 2008 That is because your syntax is wrong. In php, the else statment takes no arguements, that is what the else if statment is for, but for this purpose just change that part to: <?php function unset_register_globals() { if (ini_get('register_globals')) { foreach ($GLOBALS as $key => $value) { if (!in_array($key, array('_ENV' => 1, '_GET' => 1, '_POST' => 1, '_COOKIE' => 1, '_FILES' => 1, '_SERVER' => 1, '_REQUEST' => 1, 'GLOBALS' => 1))) { unset($GLOBALS[$key]); } else { print "Unset"; } } } } unset_register_globals(); ?> It doesn't display any output still! Any help please! Quote Link to comment Share on other sites More sharing options...
xtopolis Posted August 10, 2008 Share Posted August 10, 2008 Check what ini_get('register_globals') is returning. echo ini_get('register_globals'); But might it not be simpler to just do: $_POST=array(); $_GET=array(); $_FILES=array(); ... etc, for the ones you need? Quote Link to comment 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.