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

From: Date: Wed, 27 Aug 2003 15:31:38 +0000
Subject: note 35321 added to function.get-magic-quotes-gpc
Groups: php.notes 
Request: Send a blank email to php-notes+get-55179@lists.php.net to get a copy of this message
Here's yet another way of making code that will work regardless of whether gpc_magic_quotes is on or off: <?php if (get_magic_quotes_gpc()) { function maybeaddslashes(&$inthing) { } function maybestripslashes(&$inthing) { if (is_array($inthing)) { foreach ($inthing as $element) { $element = stripslashes($element); } } else { $inthing = stripslashes($inthing); } } } else { function maybeaddslashes(&$inthing) { if (is_array($inthing)) { foreach ($inthing as $element) { $element = addslashes($element); } } else { $inthing = addslashes($inthing); } } function maybestripslashes(&$inthing) {} } ?> You can call maybeaddslashes() before adding performing MySQL queries, or the like, and maybestripslashes() when you don't want the slashes in your GPC data. It also has the advantage that it makes the decision only once, so theoretically is slighly faster. Oh, as you can see, it will convert arrays of strings too. ---- Manual Page -- http://www.php.net/manual/en/function.get-magic-quotes-gpc.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35321 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35321&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35321&report=yes

« previous php.notes (#55179) next »