I've been going mad over this, I just can't see why it is not working.. I know the PHP validation is not complete, I'm taking one step at a time and trying to figure out why this isn't working!
Basically what I'm trying to do is stop e-mail injection with ''\n'' ''\r'' for new lines so people can't CC and use my form as spam.
It worked OK for me after I changed the form action to "" instead of ".". (I also changed the submit button mark-up so I could see it.)
Note however that the current logic will report that the email is invalid even if it's the $name value that is causing the problem. If you want to track which fields are problems, I often like to create an array of error messages, something like:
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
It says it is fine, Which the below code I thought would stop the e-mail injection.
PHP Code:
if (preg_match("/[\r\n]/", $name)) {
$errors[] = "The name '$name' is invalid.";
}
if(preg_match("/[\r\n]/", $email)) {
$errors[] = "The email: " . $_POST['email'] . " is inValid!";
}
Ok the above code doesn't work but if i put the input as ''something@something.com\n somethingelse@something.com" it finds the match
If I run this code it works and finds the match:
Are you typing a literal "\n" (back-slash and "n") in the form, or just using the return/enter key to insert a new line (which is what your pattern is testing for)?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Are you typing a literal "\n" (back-slash and "n") in the form, or just using the return/enter key to insert a new line (which is what your pattern is testing for)?
Ohh when I'm entering in the form I'm literally typing
Bookmarks