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

From: Date: Tue, 13 Jan 2004 13:38:41 +0000
Subject: note 38962 added to function.get-magic-quotes-gpc
Groups: php.notes 
Request: Send a blank email to php-notes+get-63407@lists.php.net to get a copy of this message
All this magic quoting can be very ennoying. If you like dealing yourself with quoting only when necessary (according to quoting of your RDBMS) and restore a more traditionnal way of doing things, here's a code independent of all php.ini settings (I hope) that you can use in a top-level include file, to allways get the original, unquoted GPC variables. It only requires PHP 4 >= 4.0.6 (array_map) and that you dont forget quoting vars in SQL statements. Use only the GPC superglobal arrays ($_GET, $_POST and $_COOKIE), not vars created by register_globals set to 'on'. <?php set_magic_quotes_runtime(0); if (get_magic_quotes_gpc()) { function noslashes($elem) { if (is_array($elem)) return array_map('noslashes', $elem); else return stripslashes($elem); } function nosybquot($elem) { if (is_array($elem)) return array_map('nosybquot', $elem); else return str_replace("''", "'", $elem); } $fn = ini_get('magic_quotes_sybase') ? 'nosybquot' : 'noslashes'; $_GET = array_map($fn, $_GET); $_POST = array_map($fn, $_POST); $_COOKIE = array_map($fn, $_COOKIE); } ?> ---- 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+38962 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38962&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38962&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63407) next »