PHP Code:
/*ANTISPAM WEBSITES*/
if (ereg('^www\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9]+', $_POST['comments']))
$skipit=1;
if (ereg('^[A-Za-z0-9_-]+\\.[A-Za-z0-9]+', $_POST['comments']))
$skipit=1;
if (ereg('^http\\:\\/\\/www\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9]+', $_POST['comments']))
$skipit=1;
if (ereg('^http\\:\\/\\/[A-Za-z0-9_-]+\\.[A-Za-z0-9]+', $_POST['comments']))
$skipit=1;
if ($skipit) {
header("Location: http://www.website.com/error.php");
exit;
}
The above shortens by using a flag if there is a match and redirecting in one place. This way if you change the error page it only happens in one place.
Note also I am using the short version of IF, where if you only execute ONE command, you dont need the brackets.
Shortening the REGEX -
PHP Code:
if (ereg('^[http\\:\\/\\/]*[www\\.]*[A-Za-z0-9_-]+\\.[A-Za-z0-9]+', $_POST['comments']))
I think this should work. Note the brackets. By putting a * after instead of + you indicate that it is an optional match.
Note, the ^ means search from the beginning of the comments field, so if the URL is not the first thing in comments, it will pass, so I am not sure you want it in there.