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'] == 'send')) {
place the verification code:
// Captcha check
$t = trim($HTTP_POST_VARS['verify']);
if ($t == "") {
$captcha_error = "Enter the verification code!";
$error = true;
$messageStack->add('contact', $captcha_error);
} else if (trim($_SESSION["thecode"]) == "") {
$captcha_error = "No verification code generated!";
$error = true;
$messageStack->add('contact', $captcha_error);
} else if ($_SESSION["thecode"] != strtoupper($t)) {
$captcha_error = "Invalid verification code!";
$error = true;
$messageStack->add('contact', $captcha_error);
}
else
{ // End Captcha Check
Here's the "image.php" file that produces a simple captcha image:
<?php
include_once('includes/application_top.php');
function generate_verification() {
srand((double)microtime()*1000000);
$rand = rand(0,999999999);
$thecode = substr(strtoupper(md5($rand)), 2, 5);
$thecode = str_replace("O", "A", $thecode);
$thecode = str_replace("0", "B", $thecode);
$_SESSION['thecode'] = $thecode;
}
generate_verification();
header("Content-type: image/png");
$image = imagecreate(60,20);
$background_color = imagecolorallocate ($image, 219, 236, 255);
$blue = imagecolorallocate($image, 0, 90, 190);
imagestring($image,5,8,2,$_SESSION['thecode'],$blue);
imagepng($image);
imagedestroy($image);
tep_session_register('thecode');
?>
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'] == 'send')) {
// Captcha check
$t = trim($HTTP_POST_VARS['verify']);
if ($t == "") {
$captcha_error = "Enter the verification code!";
$error = true;
$messageStack->add('contact', $captcha_error);
} else if (trim($_SESSION["thecode"]) == "") {
$captcha_error = "No verification code generated!";
$error = true;
$messageStack->add('contact', $captcha_error);
} else if ($_SESSION["thecode"] != strtoupper($t)) {
$captcha_error = "Invalid verification code!";
$error = true;
$messageStack->add('contact', $captcha_error);
}
else
{ // 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']);
}
if (tep_validate_email($email_address)) {
tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $enquiry, $name, $email_address);
tep_redirect(tep_href_link(FILENAME_CONTACT_US, 'action=success'));
} else {
$error = true;
$messageStack->add('contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
}
}
$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_CONTACT_US));
?>
-------------- and look for
<tr>
<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
<tr class="infoBoxContents">
<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td width="10" align="right"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?>
<!-- insert here the input code and add "Input Secure Code" ------ -->
Input Secure Code: <input type="text" name="verify" />
<img src="image.php" width="60" height="20" alt="Please enter the values from this image" />
<!-- -------------------------------- -->
</td>
<td align="right"><?php echo tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td>
<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
</tr>
</table>