note 74540 deleted from function.array-keys by bjori

From: Date: Tue, 17 Apr 2007 09:37:23 +0000
Subject: note 74540 deleted from function.array-keys by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125509@lists.php.net to get a copy of this message
Note Submitter: Chris Reason: bad code ---- Here's quite a nice security function I came up with. If you're using mysql to store inputtable data, this is very difficult/impossible for hackers to get by. <?php $keys = array_keys($_POST); $arraycount = count($keys); for ($z=0; $z<$arraycount; $z++) { $specialchars = array("\\\"", "\\'", "\\\\"); $replacewith = array("&quot;", "&#39;", "&#92;"); $_POST[$keys[$z]] = str_replace($specialchars, $replacewith, $_POST[$keys[$z]]); } ?> You can do the same with $_GET as well. With this you can simply add post variables into the database directly without having to worry too much about security.

« previous php.notes (#125509) next »