note 50547 deleted from function.ini-set by didou
| From: | didou@php.net | Date: | Thu, 03 Mar 2005 09:51:51 +0000 |
| Subject: | note 50547 deleted from function.ini-set by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-85852@lists.php.net to get a copy of this message | ||
Note Submitter: alan-hogan-php AT pixels and pages .com
Reason: useless
----
Thanks, php_net+NOSPAM at lazur dot com, for your helpful script!
However, when I tried using it, I noticed a little bug in it.
When a GET (probably a POST, too) is tried with a key containing a dash, I get a nonfatal but
printing error like this:
Parse error: parse error, unexpected '-', expecting ',' or ')' in
/homepages/24/d1###/htdocs/test/php/page.php(17) : eval()'d code on line 1
Parse error: parse error, unexpected '-', expecting ',' or ')' in
/homepages/24/d1###/htdocs/test/php/page.php(27) : eval()'d code on line 1
Plainly what is happening is the code tries to unset a variable that would never exist anyway (var
names can't contain dashes).
I'm not sure if my fix is 100% good -- it probably isn't -- but here it is anyway. It
doesn't bother UNSETting when the key contains a dash, asterisk, less-than, or greater-than. I
imagine a better way to do this would be to make sure the name contains a valid var name instead of
targetting just those few bad characters.
<?php
if (ini_get(register_globals)) // If register globals are enabled
{
// Unset $_GET keys
foreach ($_GET as $get_key => $get_value) {
if (!strpos($get_key,'-') and !strpos($get_key,'*') and
!strpos($get_key,'<') and !strpos($get_key,'>')){
eval("unset(\${$get_key});");
}
}
// Unset $_POST keys
foreach ($_POST as $post_key => $post_value) {
if (!strpos($post_key,'-') and !strpos($post_key,'*') and
!strpos($post_key,'<') and !strpos($post_key,'>')){
eval("unset(\${$post_key});");
}
}
// Unset $_REQUEST keys
foreach ($_REQUEST as $request_key => $request_value) {
if (!strpos($request_key,'-') and !strpos($request_key,'*') and
!strpos($request_key,'<') and !strpos($request_key,'>')){
eval("unset(\${$request_key});");
}
}
}
?>