PHPJavascript

Web Development Guide – My Personal Library of Tutorials and Scripts

Website Spammers / Web Spammers / Comment Spammers and visual check (CAPTCHA)

August14

Learn how to avoid spammers from bombarding you website forums, contactus page, guestbooks etc.

The web is awash with spambots that attack contact forms, guestbooks, forums etc.

I didn’t consider spam a big threat and had not taken any measures to prevent www.phpjavascript.com from them. As a result my forums and contact us web pages were filled with spam mostly pornographic stuff. I was so shocked cuz every forum on my website had 30-50 spam replies and all dirt stuff. And then I took the step of implementing CAPTCHA on my website.

CAPTCHA is basically a test to tell humans apart from computers (spambots in this case) that relies on the user entering a string of characters presented to them in an image.

I have selected an image validator (CAPTCHA) from www.gscripts.net. Very simple to implement and use.

Requirements

1. Apache 1 or 2
2. PHP 4 or 5
3. GD 2 with true type support. (Graphics library don’t worry most of the hosting companies have support for GD)

Demo

Click here to view the demo

I have implemented this image validator on the contact page of www.phpjavascript.com/ . Download the complete file from the top of this page.

If you want to implement it yourself follow the steps.

Step 1: Copy paste the following in the head tag <head></head>

<? session_start();
$ts = time(); ?>
<script language="JavaScript"><!--
ts = <?= $ts ?>;
--></script>

Step 2: Copy paste the following in between the html form

<img id="__code__" src="code.php?id=<?= $ts ?>" style="border:1px solid #000000" /><a href="no_matter" onClick="document.getElementById('__code__').src = 'code.php?id=' + ++ts; return false">click for new code</a><br />
<input type="text" name="code" width="350" />

Save the file as contact.php

Step 3: Copy paste the following in the submit page (submitcontact.php)

if(md5(strtoupper($_POST['code'])) <> $_SESSION['__img_code__'])
{ ?>
<script language="JavaScript">
window.open("contact.php", "_self")
</script>
<? } else { ?>

**** the required text ***

<? } ?>

Save the file as submitcontact.php

Step 4: Download the image validation script, extract the folder and place the files you were working on this folder (in this case contact.php and submitcontact.php)

posted under Security

Email will not be published

Website example

Your Comment:

 

2,885 spam comments
blocked by
Akismet