Spam-Proofing Your Website
Anyone who operates their own website knows that you need to provide forms in your site for visitors to contact you. The big challenge is providing easy form access to your visitors, without letting SPAM flood your email inbox or database. The techniques described in this article tell you how to reduce the amount of SPAM.
1, Form Validation on the Client Side using Javascript
Client Side Forms validation is essential -- it saves time and bandwidth. It points out to the user where they've gone wrong in
filling out the form.
Here is a sample of client side form validation using javascript
http://www.gdsland.com/others/contact_us.php
****** Javascript Code **************
<script language="JavaScript">
function checkCatalogForm(obj)
{
var regex = /^[A-Za-z_0-9'\.\-]+@[A-Za-z_0-9'\.\-]+(\.\w+)+$/;
var emailTest = regex.exec(document.catalog_form.bio_email.value);
if(document.catalog_form.bio_name.value == '')
{
alert( "You must supply a first name. " );
document.catalog_form.bio_name.focus();
return false;
}
else if(!emailTest)
{
alert("You must supply a valid email address.");
document.catalog_form.bio_email.focus();
document.catalog_form.bio_email.value = '';
return false;
}
else
{
return true;
}
}
</script>
************ HTML Code *********
<form method="POST" action="xxxx.php" name="catalog_form" onSubmit="return checkCatalogForm();">
<tr>
<td colspan="2" align="right" valign="top">
<p align="center">Fields marked with an asterisk (<strong><font color="#FF0000">*</font></strong>)
are required.</p></td>
</tr>
<tr>
<td width="50%" align="right" valign="top"><strong><font color="#FF0000">*</font>
Name : </strong></td>
<td width="50%" align="left" valign="top"> <input name="bio_name" type="text" size="50" >
</tr>
<tr>
<td align="right" valign="top"><strong><font color="#FF0000">
*</font> Email : </strong> </td>
<td valign="top" align="left"> <input name="bio_email" type="text" size="50" >
</tr>
<tr>
<td height="26" align="right" valign="center"><strong>Which product
are you interested?</strong> </td>
<td valign="top" align="left"><input name="product" type="text" size="50" >
</td>
</tr>
<tr>
<td height="26" align="right" valign="center"><strong>How did you
hear about us? </strong> </td>
<td valign="top" align="left">
<input type="other" name="other" size="50" > </td>
</tr>
<tr>
<td height="26" align="right" valign="top"><strong>Questions or
Comments :</strong> </td>
<td valign="top" align="left"> <textarea name="bio_comments" cols="40" rows="5"></textarea></td>
</tr>
<tr>
<td height="26" align="right" valign="top"> </td>
<td valign="top" align="left"><input type="submit" value="Submit Request" name="B1">
<input type="reset" value="Reset Form" name="B2"></td>
</tr>
<tr>
<td height="26" colspan="2" align="right" valign="top"> </td>
</tr>
</form>
2, Form Validation on the Server Side using Javascript
On the server side, you need to check if user fill all required fields.
3, Using verification word to stop robots to send spam
"verification word" is an image generated by system randomly and dynanically.
A spambot cannot submit a form without providing correct text in the image.
Here is a demo site using verification word.
http://www.gdsland.com/PHPSpamTerminator/verification_demo.php |