Adding Captcha to a preexisting Contact Form

Hello all,

I was asked to add a captcha to a form on a website that I’m updating. You can see it here:

I am not good at hardcoding so I’m kind lost. I did some research and I think I need to use this code called OpenCaptcha.

The code sounds easy enough but I have no clue how to install it into my original code.

Here’s the directions:

On the form page, dynamically create a filename ({random}.jpgx and print to the screen both an >img< and an >input value={image name}< tag including that name

Use the current timestamp and your domain name as the random number { 200705041231mydomainname.jpgx }
Add -{height}-{width} to specify the size { 200705041231mydomainname-80-240.jpgx will make a 80px tall and 240px wide image }

On the form page, add a text field for the user to enter the Captcha code

On the processing page, check to see if{imageName}&ans={users Answer} returns the word “pass” or “fail”
Below is a really simple sample PHP code.

Can someone explain this: On the form page, dynamically create a filename ({random}.jpgx and print to the screen both an >img< and an >input value={image name}< tag including that name ?

Here’s their example code:

Login Page

if($_GET[‘opencaptcha’]==‘failed’) { echo “<script>alert(‘You Did Not Fill In The Security Code Correctly’);</script>”;}
$date = date(“Ymd”);
$rand = rand(0,9999999999999);
$height = “80”;
$width = “240”;
$img = “$date$rand-$height-$width.jpgx”;
echo “<input type=‘hidden’ name=‘img’ value=‘$img’>”;
echo “<a href=‘’><img src=‘$img’ height=‘$height’ alt=‘captcha’ width=‘$width’ border=‘0’ /></a><br />”;
echo “<input type=text name=code value=‘Enter The Code’ size=‘35’ />”;

Processing Page

if(file_get_contents(““.$_POST[‘code’].”&img=”.$_POST[‘img’])==‘pass’) {
} else {
header(“LOCATION: “.$_SERVER[‘HTTP_REFERER’].”?opencaptcha=failed”);

I was going to pay someone to do this for me but I’d really like to learn how to do this myself. Thanks for reading.

If it helps, Google’s recaptcha is an easy to use system.

Hi lukasgraphics,

Below url might help you :slight_smile:

Thanks guys. I’m going to try the google php one first. Your responses really helped.


I got my Captcha image to show up but now I don’t know how to make my verify page and functions to work. I used the Google PHP method. My form can be seen here:

Right now my verify.php file is as follows:

$privatekey = “my private #”;
$resp = recaptcha_check_answer ($privatekey,

if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
"(reCAPTCHA said: " . $resp->error . “)”);
} else {
// Your code here to handle a successful verification

What I’m trying to achieve is have this form be mailed to two people at this business. I’d also like the person filling out the form to be contacted via that the form was successful. Finally, I’d like a message on the page where the form is say “There was a mistake with your Captcha entry” or “Thanks for contacting us. We will be in contact shortly”.

Pretty simple but not for an amateur like myself. I am not asking for someone to do this for me but some help as to where to start. I’d rather learn how to do this than to have to sub it out to someone.


Don’t know about you but i think that recaptcha is so ugly. Here is my copy and paste captcha

Yes, if I was my client I’d say it was ugly. I just want to find something I can get working. I’ll give your code a shot.


I got your code to work here:

How do I get your code to work with the rest of my form now? I want it to mail to a email the rest of the forms entries. Also is there a way to have the success or error information show up on this page kind of like it was originally done here:

Thanks for your continued support. I think your way looks much cleaner and I can understand the code as a beginner.

There are a number of different visual themes that it has, as well as custom ones so you can have more control, so that you can adjust it to fit better your site.

Ahhh. Bookmarked. The clean theme is quite usable.

Update. I found a great code with clean Recaptcha. Hopefully, this can help someone else out there.