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]); } } } } ?> Link to comment https://forums.phpfreaks.com/topic/118990-does-it-work/ 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. Link to comment https://forums.phpfreaks.com/topic/118990-does-it-work/#findComment-612726 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! Link to comment https://forums.phpfreaks.com/topic/118990-does-it-work/#findComment-612735 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){ Link to comment https://forums.phpfreaks.com/topic/118990-does-it-work/#findComment-612738 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" } Link to comment https://forums.phpfreaks.com/topic/118990-does-it-work/#findComment-612740 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(); ?> Link to comment https://forums.phpfreaks.com/topic/118990-does-it-work/#findComment-612744 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(); ?> Link to comment https://forums.phpfreaks.com/topic/118990-does-it-work/#findComment-612761 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! Link to comment https://forums.phpfreaks.com/topic/118990-does-it-work/#findComment-612966 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? Link to comment https://forums.phpfreaks.com/topic/118990-does-it-work/#findComment-613115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.