note 38962 deleted from function.get-magic-quotes-gpc by nlopess

From: Date: Tue, 13 Jan 2004 14:54:49 +0000
Subject: note 38962 deleted from function.get-magic-quotes-gpc by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-63441@lists.php.net to get a copy of this message
Note Submitter: christophe@NOSPAM.publicityweb.com ---- 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); } ?>

« previous php.notes (#63441) next »