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