Simple captcha for oscommerce contact form

Embed the captcha image by calling a php script in "contact_us.php":

<input type="text" name="verify" />
<img src="/image.php" width="60" height="20" alt="Please enter the values from this image" />

Edit contact_us.php file and exactly after the below line:

  if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action&#039;] == 'send')) {

place the verification code:

        // Captcha check
    &nbsp;   $t = trim($HTTP_POST_VARS['verify']);
    &nbsp;   if ($t == "") {
    &nbsp;    &nbsp;    &nbsp; $captcha_error = "Enter the verification code!";
    &nbsp;    &nbsp;    &nbsp; $error = true;
    &nbsp;    &nbsp;    &nbsp; $messageStack->add('contact', $captcha_error);
    &nbsp;   } else if (trim($_SESSION["thecode&quot;]) == "") {
    &nbsp;    &nbsp;    &nbsp; $captcha_error = "No verification code generated!";
    &nbsp;    &nbsp;    &nbsp; $error = true;
    &nbsp;    &nbsp;    &nbsp; $messageStack->add('contact', $captcha_error);
    &nbsp;   } else if ($_SESSION["thecode"] != strtoupper($t)) {
    &nbsp;    &nbsp;    &nbsp; $captcha_error = "Invalid verification code!";
    &nbsp;    &nbsp;    &nbsp; $error = true;
    &nbsp;    &nbsp;    &nbsp; $messageStack->add('contact', $captcha_error);
    &nbsp;   }
    &nbsp;   else
    &nbsp;   { // End Captcha Check

Here's the "image.php" file that produces a simple captcha image:

<?php
include_once(<span style="color: #DD0000">'includes/application_top.php'
);

function
generate_verification() {
    &nbsp;  
srand((double) style="color: #0000BB">microtime style="color: #007700">()*1000000);
    &nbsp;  
$rand = rand(0,999999999 style="color: #007700">);
    &nbsp;   $thecode = substr(strtouppern style="color: #007700">(md5($rand)), 2, 5);
    &nbsp;  
$thecode = str_replacean style="color: #007700">("O", "A", $thecode);
    &nbsp;  
$thecode = str_replacean style="color: #007700">("0", "B", $thecode);
    &nbsp;  
$_SESSION style="color: #007700">['thecode' style="color: #007700">] = $thecode;
}

generate_verification();
header("Content-type: image/png");
$image = imagecreatean style="color: #007700">(60,20);
$background_color = imagecolorallocate ($image, 219, 236, 255);
$blue = imagecolorallocatepan>($image, 0, 90, 190);
imagestringan style="color: #007700">(
$image,5,8,2,$_SESSION style="color: #007700">['thecode' style="color: #007700">],$blue);
imagepng($image);
imagedestroypan style="color: #007700">($image);
tep_session_register</span>('thecode' style="color: #007700">);
?>

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Thank you!

At last a captcha that is readable....

does work

hi, i tried this code it doesnt work when the email is correct it doesnt check the captcha

chinese oscommerce captcha problem

The captcha code works well in english oscommerce. But in chinese language, the verification code just not generated. Any idea? Thanks.

STpd Q

first of thanks for this little treasure! this is the only captcha i got working and i know it says "Simple" but is there a way to put a little bit of distractions on the captcha image generated? just a tiny bit more anti bot security.

Where the box to enter the code

Just wandering if there was a text box for the code to be typed into.

Yes, the text box should be

Yes, the text box should be as:

<input type="text" name="verify" />
<img src="/image.php" width="60" height="20" alt="Please enter the values from this image" />

Thanks for bring this up, I have modified the above instruction set and included the info.

There is the original code

There is the original code after the last else statement, that's why it is there.

Bug Fix

To many curlies, lol. Curly bracket needs to be removed for it to work.

else
// End Captcha Check

Doesn't work for me

Hi folks. Set this up. Capcha shows but if incorrect capcha used the email form is still processed.

G.L.

work perfectly ----> contact_us.php

----------------------------------------
if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action&#039;] == 'send')) {


     // Captcha check
    &nbsp;   $t = trim($HTTP_POST_VARS['verify']);
    &nbsp;   if ($t == "") {
    &nbsp;    &nbsp;    &nbsp; $captcha_error = "Enter the verification code!";
    &nbsp;    &nbsp;    &nbsp; $error = true;
    &nbsp;    &nbsp;    &nbsp; $messageStack->add('contact', $captcha_error);
    &nbsp;   } else if (trim($_SESSION["thecode&quot;]) == "") {
    &nbsp;    &nbsp;    &nbsp; $captcha_error = "No verification code generated!";
    &nbsp;    &nbsp;    &nbsp; $error = true;
    &nbsp;    &nbsp;    &nbsp; $messageStack->add('contact', $captcha_error);
    &nbsp;   } else if ($_SESSION["thecode"] != strtoupper($t)) {
    &nbsp;    &nbsp;    &nbsp; $captcha_error = "Invalid verification code!";
    &nbsp;    &nbsp;    &nbsp; $error = true;
    &nbsp;    &nbsp;    &nbsp; $messageStack->add('contact', $captcha_error);
    &nbsp;   }
    &nbsp;   else
    &nbsp;   {     ;    // End Captcha Check

    $name = tep_db_prepare_input($HTTP_POST_VARS['name']);
    $email_address = tep_db_prepare_input($HTTP_POST_VARS['email']); />    $enquiry = tep_db_prepare_input($HTTP_POST_VARS['enquiry']);<br />   }
    if (tep_validate_email($email_address)) {
    &nbsp; tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $enquiry, $name, $email_address);

    &nbsp; tep_redirect(tep_href_link(FILENAME_CONTACT_US, 'action=success'));<br />    } else {
    &nbsp; $error = true;

    &nbsp; $messageStack->add('contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
    }
  }

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_CONTACT_US));
?>
--------------  and look for
<tr>
    &nbsp;   <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox"><br />    &nbsp;     <tr class="infoBoxContents&quot;>
    &nbsp;    &nbsp;  <td><table border="0" width="100%" cellspacing="0" cellpadding="2"><br />    &nbsp;    &nbsp;    <tr>
    &nbsp;    &nbsp;    &nbsp; <td width="10" align="right">an style="color: #000000"><?php echo tep_draw_separatorpan>('pixel_trans.gif'an>, '10', '1'); ?>r /><!--  insert here the input code and add "Input Secure Code"   &nbsp; ------ -->
    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;     Input Secure Code: <input type="text" name="verify" />
<img src="image.php" width="60" height="20" alt="Please enter the values from this image" />
<!-- --------------------------------  -->
    &nbsp;    &nbsp;    &nbsp; </td>
    &nbsp;    &nbsp;    &nbsp; <td align="right">an style="color: #000000"><?php echo tep_image_submitn>('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?>&lt;/td>
    &nbsp;    &nbsp;    &nbsp; <td width="10"><?php echo tep_draw_separatorpan>('pixel_trans.gif'
an>, '10', '1'); ?>&lt;/td>
    &nbsp;    &nbsp;    </tr>
    &nbsp;    &nbsp;  </table>

Comment