note 62171 added to function.get-magic-quotes-gpc
| From: | publicNOSPAMatsyranidedotcom at osu1 dot php dot net | Date: | Tue, 21 Feb 2006 21:03:06 +0000 |
| Subject: | note 62171 added to function.get-magic-quotes-gpc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104161@lists.php.net to get a copy of this message | ||
In regards to the comment(s) on sybase, if you read the documentation carefully you will see that
you will not need a specific case for when sybase is active as stripslashes changes accordingly
(stupid as one might want to use it for actually stripping slashes), however that's the case,
and so, stripslashes will always properly treat the incoming escaped data. So the very same function
can be used for both gpc and sybase.
However, many suggests that you run array_map (array_walk is slower as it works on refs) and note as
previously said by "php at kaiundina dot de" it doesn't fully revert the process as
keys are also escaped. But then again, in PHP you don't want to spend too long on this as it
quickly eats of the power, and anyway, who really uses quotes in the keys anway.
However, something you might want to consider when stripping slashes from the superglobals is that
it is not only really about $_GET, $_POST and $_REQUEST, it also concerns $_COOKIE, $_FILES, $_ENV
and $_SERVER ... the only one not affected is $_SESSION. Though, stripping $_ENV and $_SERVER is
commonly just a waste of processing power and rarely matters.
A speed gain can however be gotten from not stripping $_REQUEST but instead:
<?php $_REQUEST = array_merge($_GET, $_POST, $_COOKIE); ?>
I personally leave $_COOKIE out as I think it's better of alone and might just mess up things
otherwise.
The following code is what I am using, and I have not been able to get it any faster (?: and ref is
slow) and still maintain full coverage (however I rarely parse all of them though, you can gain a
few ticks by inlining the main strip-function and by checking if they are empty), note that it does
NOT properly remove slashes from keys.
<?php
set_magic_quotes_runtime(0);
if(get_magic_quotes_gpc() || ini_get('magic_quotes_sybase')) {
$_GET = magic_quotes_strip($_GET);
$_POST = magic_quotes_strip($_POST);
$_COOKIE = magic_quotes_strip($_COOKIE);
$_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
$_FILES = magic_quotes_strip($_FILES);
$_ENV = magic_quotes_strip($_ENV);
$_SERVER = magic_quotes_strip($_SERVER);
}
function magic_quotes_strip($mixed) {
if(is_array($mixed))
return array_map('magic_quotes_strip', $mixed);
return stripslashes($mixed);
}
?>
This should work for any setup, including sybase (as of the stripslashes behaviour).
----
Server IP: 129.16.214.50
Probable Submitter: 217.209.48.199
----
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+62171
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62171&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62171&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62171&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62171&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62171&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62171&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62171&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+62171&report=yes
Search -- http://master.php.net/manage/user-notes.php