note 74540 added to function.array-keys
| From: | Chris at osu1 dot php dot net | Date: | Mon, 16 Apr 2007 16:52:40 +0000 |
| Subject: | note 74540 added to function.array-keys | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125452@lists.php.net to get a copy of this message | ||
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(""", "'", "\");
$_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.
----
Server IP: 87.124.64.96
Probable Submitter: 84.51.154.107
----
Manual Page -- http://www.php.net/manual/en/function.array-keys.php
Edit -- https://master.php.net/note/edit/74540
Del: integrated -- https://master.php.net/note/delete/74540/integrated
Del: useless -- https://master.php.net/note/delete/74540/useless
Del: bad code -- https://master.php.net/note/delete/74540/bad+code
Del: spam -- https://master.php.net/note/delete/74540/spam
Del: non-english -- https://master.php.net/note/delete/74540/non-english
Del: in docs -- https://master.php.net/note/delete/74540/in+docs
Del: other reasons-- https://master.php.net/note/delete/74540
Reject -- https://master.php.net/note/reject/74540
Search -- https://master.php.net/manage/user-notes.php