note 47355 added to function.get-magic-quotes-gpc

From: Date: Fri, 12 Nov 2004 20:00:17 +0000
Subject: note 47355 added to function.get-magic-quotes-gpc
Groups: php.notes 
Request: Send a blank email to php-notes+get-80448@lists.php.net to get a copy of this message
In the example above, the author forgets to include $_REQUEST, which is also slashed (using PHP 4.3.8). It's good practice to include a routine to "unslash" or "slash" variables, if something happens that isn't to your expectation. However your PHP is written to depend on this option, it becomes important to support either when or if others deploy your code. --------------------------------------------------------------------- If you have written for having this option disabled: --------------------------------------------------------------------- if (get_magic_quotes_gpc()) unfck_gpc(); function unfck($v) { return is_array($v) ? array_map('unfck', $v) : stripslashes($v); } function unfck_gpc() { foreach (array('POST', 'GET', 'REQUEST', 'COOKIE') as $gpc) $GLOBALS["_$gpc"] = array_map('unfck', $GLOBALS["_$gpc"]); } --------------------------------------------------------------------- If you have written for having this option enabled: --------------------------------------------------------------------- if (!get_magic_quotes_gpc()) unfck_gpc(); function unfck($v) { return is_array($v) ? array_map('unfck', $v) : addslashes($v); } function unfck_gpc() { foreach (array('POST', 'GET', 'REQUEST', 'COOKIE') as $gpc) $GLOBALS["_$gpc"] = array_map('unfck', $GLOBALS["_$gpc"]); } --------------------------------------------------------------------- Including either code block, depending on how your PHP is written, will ensure that it will operate the same regardless of this configuration option. ---- Manual Page -- http://www.php.net/manual/en/function.get-magic-quotes-gpc.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47355 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47355&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47355&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47355&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47355&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47355&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47355&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47355&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#80448) next »