note 92496 added to security.database.sql-injection

From: Date: Mon, 27 Jul 2009 14:31:22 +0000
Subject: note 92496 added to security.database.sql-injection
Groups: php.notes 
Request: Send a blank email to php-notes+get-158773@lists.php.net to get a copy of this message
i just played around with the array_walk function. It suddenly struck me that almost all super globals are arrays. So what i discovered was that i can apply the array_walk function to the super globals. Doing so you automatically run a function call through the super globals With this piece of code i wrote you should be able to secure most of you input data. <?php class secure { function secureSuperGlobalGET(&$value, $key) { $_GET[$key] = htmlspecialchars(stripslashes($_GET[$key])); $_GET[$key] = str_ireplace("script", "blocked", $_GET[$key]); $_GET[$key] = mysql_escape_string($_GET[$key]); return $_GET[$key]; } function secureSuperGlobalPOST(&$value, $key) { $_POST[$key] = htmlspecialchars(stripslashes($_POST[$key])); $_POST[$key] = str_ireplace("script", "blocked", $_POST[$key]); $_POST[$key] = mysql_escape_string($_POST[$key]); return $_POST[$key]; } function secureGlobals() { array_walk($_GET, array($this, 'secureSuperGlobalGET')); array_walk($_POST, array($this, 'secureSuperGlobalPOST')); } } ?> Note that you can modify this in anyway to suit your needs. The Script has been tested. ---- Server IP: 209.41.74.194 Probable Submitter: 91.149.7.173 ---- Manual Page -- http://www.php.net/manual/en/security.database.sql-injection.php Edit -- https://master.php.net/note/edit/92496 Del: integrated -- https://master.php.net/note/delete/92496/integrated Del: useless -- https://master.php.net/note/delete/92496/useless Del: bad code -- https://master.php.net/note/delete/92496/bad+code Del: spam -- https://master.php.net/note/delete/92496/spam Del: non-english -- https://master.php.net/note/delete/92496/non-english Del: in docs -- https://master.php.net/note/delete/92496/in+docs Del: other reasons-- https://master.php.net/note/delete/92496 Reject -- https://master.php.net/note/reject/92496 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158773) next »