note 50547 added to function.ini-set

From: Date: Thu, 03 Mar 2005 00:50:04 +0000
Subject: note 50547 added to function.ini-set
Groups: php.notes 
Request: Send a blank email to php-notes+get-85837@lists.php.net to get a copy of this message
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});"); } } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.ini-set.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50547 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50547&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50547&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50547&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50547&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50547&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50547&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85837) next »