Jump to content

Does it work?


Superian

Recommended Posts

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.