PHP Contact form with image verification
July 22nd, 2007 Noor
In this tutorial im going to show to add an image verification code Captcha to your contact form to avoid Spam in easy steps.
In the php file where you are verifying the captcha image and processing other information place the following code preferably at the top of the page since that we are going to use sessions.
Verrifying th image can be done this way:
The following code should be save as imagebuilder.php where here we create the image, the code is commented as you have notices with lots of tweaks to customize it the way you need but i have just kept it as simple as possible.
Notice the at the end of the code
where here we are instantiating a session variable that will store the password and will use while processing the form
save the following code as settings.php where it contains variables to be used by the imagebuilder.php
Now finally its time to place the image and a in the main contact form with a textbox to enter the verification code of the image
place the following code where you want the image to appear
echo ‘<p><a href=”http://’.$_SERVER[’HTTP_HOST’].htmlentities($_SERVER[’PHP_SELF’]).
‘” onclick=”document.getElementById(\’captcha\’).src=\’http://’.
$_SERVER[’HTTP_HOST’].”imagebuilder.php”.
‘; return false;”>Cant see it</a></p>’.”\n”.
‘<p><img id=”captcha” src=”imagebuilder.php” alt=”"></p>’.”\n”;
sorry i coun’t format the above code. just copy and paste it and everything should be fine.
Place a textbox on the form that accepts the cerification code:
that’s it, everything should work fine after that..
hope that this tutorial was informative and thank you for viewing
Posted in PHP | 1 Comment »
