| 8:01 pm on Mar 25, 2003 (gmt 0)|
The problem is that I don't think the snippet does anything that you think it does. Why not try explaining your methodology in words and we can see if we can't convert that to code.
| 9:27 pm on Mar 25, 2003 (gmt 0)|
What I'm trying to do is restrict the characters which can be susubmitted by the form in order to limit potential hacking to the text file it writes to.
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.
| 9:32 pm on Mar 25, 2003 (gmt 0)|
I think in your foreach you could have a regular expression that makes sure all chars in the var are in the allowed set.
I am not the regex guru here so maybe someone could offer one?
| 9:40 pm on Mar 25, 2003 (gmt 0)|
$save = preg_replace [php.net]("'[^a-zA-Z0-9]'", '', $unsave);
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.
| 9:45 pm on Mar 25, 2003 (gmt 0)|
Most of the time when I do data checking I use specific patterns/tests for specific fields. A phone number one way, an email another. Error checking always depends on what data you are receiving and what you plan on doing with it. Also on the possible vulnerabilities of any given action.
For example an upload field would need more rigorous checks to prevent malicious code being unserted onto your server.