Forum Moderators: coopster
$safe_vars = array("A-Z", "a-z", "0-9");
foreach ($_POST as $key => $value) {
$safe_vars[$key] = htmlspecialchars($value);
}
I was trying to accept only letters and numerals, and also the symbols for:
at @, dash-, and underscore _
Perhaps I am going about this entirely wrong.
will delete all characters that are not simple letters and numbers.
However, whatīs save and what isnīt will depend on the context. When you output the input as HTML then htmlspecialchars [php.net] is all you really need to make sure that the output is save. When you pass the input to the shell you might want to use escapeshellcmd [php.net]. The method you suggested is rather brute force and eliminates more than really necessary in most cases.
Andreas
For example an upload field would need more rigorous checks to prevent malicious code being unserted onto your server.