#39859 [NEW]: Documentation: Disabling Magic Quotes Example Flawed

From: Date: Sun, 17 Dec 2006 20:19:25 +0000
Subject: #39859 [NEW]: Documentation: Disabling Magic Quotes Example Flawed
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969374617@lists.php.net to get a copy of this message
From: niraj6 at yahoo dot com Operating system: Windows XP SP2 PHP version: Irrelevant PHP Bug Type: Documentation problem Bug description: Documentation: Disabling Magic Quotes Example Flawed Description: ------------ PHP's magic quotes function has the strange behavior of not adding slashes to top level keys in GPC key/value pairs but adding the slashes in deeper level keys. To demonstrate, a URI of: example.php?a'b[c'd]=e'f produces: array("a'b" => array("c\'d" => "e\'f")) The current example for removing magic quotes does not do anything to keys, so after running stripslashes_deep, you would end up with: array("a'b" => array("c\'d" => "e'f")) Which, needless to say, is wrong. As if you had magic quotes off, it would have been: array("a'b" => array("c'd" => "e'f")) I have written a snippet of code compatible with PHP 4.0.0 and above that handles this correctly: if (get_magic_quotes_gpc()) { function undoMagicQuotes($array, $topLevel=true) { $newArray = array(); foreach($array as $key => $value) { if (!$topLevel) { $key = stripslashes($key); } if (is_array($value)) { $newArray[$key] = undoMagicQuotes($value, false); } else { $newArray[$key] = stripslashes($value); } } return $newArray; } $_GET = undoMagicQuotes($_GET); $_POST = undoMagicQuotes($_POST); $_COOKIE = undoMagicQuotes($_COOKIE); $_REQUEST = undoMagicQuotes($_REQUEST); } Perhaps you should replace the example in the manual with my code snippet. Oh and I have left a comment there too for users who visit the page before you guys fix it. So someone could delete that once it's fixed. -- Edit bug report at http://bugs.php.net/?id=39859&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39859&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39859&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39859&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39859&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39859&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39859&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39859&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39859&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39859&r=support Expected behavior: http://bugs.php.net/fix.php?id=39859&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39859&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39859&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39859&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39859&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39859&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39859&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39859&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39859&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39859&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39859&r=mysqlcfg

« previous php.doc (#969374617) next »