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

From: Date: Sat, 11 Oct 2003 00:00:43 +0000
Subject: note 36478 added to function.get-magic-quotes-gpc
Groups: php.notes 
Request: Send a blank email to php-notes+get-58216@lists.php.net to get a copy of this message
To make my scripts as slashproof as possible, I find it most convenient to disable set_magic_quotes_runtime and, if get_magic_quotes_gpc returns 0, step through the $_GET, $_POST, and $_COOKIE arrays and add slashes to everything. This ensures that any database operations I perform using user-supplied data will be safe, and I won't need to strip slashes from any data coming out of the database before displaying it. The only thing I'll need to remember is to strip slashes from any data that I display straight from the GET/POST/COOKIE arrays, but that's a minor inconvenience. This code also elegantly handles nested arrays within GET/POST/COOKIE data. <? set_magic_quotes_runtime(0); if (get_magic_quotes_gpc() == 0) { function magicSlashes($element) { if (is_array($element)) return array_map("magicSlashes", $element); else return addslashes($element); } // Add slashes to all incoming GET/POST/COOKIE data. $_GET = array_map("magicSlashes", $_GET); $_POST = array_map("magicSlashes", $_POST); $_COOKIE = array_map("magicSlashes", $_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+36478 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36478&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36478&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58216) next »