note 62171 deleted from function.get-magic-quotes-gpc by philip

From: Date: Tue, 27 Jun 2006 06:38:03 +0000
Subject: note 62171 deleted from function.get-magic-quotes-gpc by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114339@lists.php.net to get a copy of this message
Note Submitter: publicNOSPAM at syranide dot com ---- 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).

« previous php.notes (#114339) next »