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['ac tion']) && ($HTTP_GET_VARS['action 039;] == 'send')) {
place the verification code:
// Captcha check
&nbs p; $t = trim($HTTP_POST_VARS['ver ify']);
&nbs p; if ($t == "") {
&nbs p; &nbs p; &nbs p; $captcha_error = "Enter the verification code!";
&nbs p; &nbs p; &nbs p; $error = true;
&nbs p; &nbs p; &nbs p; $messageStack->add('co ntact', $captcha_error);
&nbs p; } else if (trim($_SESSION["thecode& quot;]) == "") {
&nbs p; &nbs p; &nbs p; $captcha_error = "No verification code generated!";
&nbs p; &nbs p; &nbs p; $error = true;
&nbs p; &nbs p; &nbs p; $messageStack->add('co ntact', $captcha_error);
&nbs p; } else if ($_SESSION["thecode" ] != strtoupper($t)) {
&nbs p; &nbs p; &nbs p; $captcha_error = "Invalid verification code!";
&nbs p; &nbs p; &nbs p; $error = true;
&nbs p; &nbs p; &nbs p; $messageStack->add('co ntact', $captcha_error);
&nbs p; }
&nbs p; else
&nbs p; { // 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 () {
&nbs p; srand((double) style="color: #0000BB">microtime style="color: #007700">()*1000000);
&nbs p; $rand = rand(0,999999999 style="color: #007700">);
&nbs p; $thecode = substr(strtoupper n style="color: #007700">(md5($rand)), 2, 5);
&nbs p; $thecode = str_replace an style="color: #007700">("O", "A", $thecode);
&nbs p; $thecode = str_replace an style="color: #007700">("0", "B", $thecode);
&nbs p; $_SESSION style="color: #007700">['thecode' style="color: #007700">] = $thecode;
}
generate_verification ();
header("Content-type: image/png");
$image = imagecreate an style="color: #007700">(60,20);
$background_color = imagecolorallocate ($image, 219, 236, 255);
$blue = imagecolorallocatepan>($image, 0, 90, 190);
imagestring an 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">);
?>
- sandip's blog
- Login or register to post comments
Comments
At last a captcha that is readable....
hi, i tried this code it doesnt work when the email is correct it doesnt check the captcha
The captcha code works well in english oscommerce. But in chinese language, the verification code just not generated. Any idea? Thanks.
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.
Just wandering if there was a text box for the code to be typed into.
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 after the last else statement, that's why it is there.
To many curlies, lol. Curly bracket needs to be removed for it to work.
else
// End Captcha Check
Hi folks. Set this up. Capcha shows but if incorrect capcha used the email form is still processed.
G.L.
------------------------------ ---------- tion']) && ($HTTP_GET_VARS['action 039;] == 'send')) {
p; $t = trim($HTTP_POST_VARS['ver ify']); p; if ($t == "") { p; &nbs p; &nbs p; $captcha_error = "Enter the verification code!"; p; &nbs p; &nbs p; $error = true; p; &nbs p; &nbs p; $messageStack->add('co ntact', $captcha_error); p; } else if (trim($_SESSION["thecode& quot;]) == "") { p; &nbs p; &nbs p; $captcha_error = "No verification code generated!"; p; &nbs p; &nbs p; $error = true; p; &nbs p; &nbs p; $messageStack->add('co ntact', $captcha_error); p; } else if ($_SESSION["thecode" ] != strtoupper($t)) { p; &nbs p; &nbs p; $captcha_error = "Invalid verification code!"; p; &nbs p; &nbs p; $error = true; p; &nbs p; &nbs p; $messageStack->add('co ntact', $captcha_error); p; } p; else p; {   ; // End Captcha Check
T_VARS['name']); T_VARS['email']); T_VARS['enquiry']);< br /> } ress)) { p; tep_mail(STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, EMAIL_SUBJECT, $enquiry, $name, $email_address);
p; tep_redirect(tep_href_link(FIL ENAME_CONTACT_US, 'action=success'));< br /> } else { p; $error = true;
p; $messageStack->add('co ntact', ENTRY_EMAIL_ADDRESS_CHECK_ERRO R);
LE, tep_href_link(FILENAME_CONTACT _US)); p; <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">< br /> &nbs p; <tr class="infoBoxContents&qu ot;> p; &nbs p; <td><table border="0" width="100%" cellspacing="0" cellpadding="2">< br /> &nbs p; &nbs p; <tr> p; &nbs p; &nbs p; <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" &n bsp; ------ --> p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; Input Secure Code: <input type="text" name="verify" /> -- --> p; &nbs p; &nbs p; </td> p; &nbs p; &nbs p; <td align="right"> an style="color: #000000"><?php echo tep_image_submitn>('button_continue.gif' , IMAGE_BUTTON_CONTINUE ); ?>&l t;/td> p; &nbs p; &nbs p; <td width="10"><?php echo tep_draw_separatorpan>('pixel_trans.gif'an>, '10', '1'); ?>&l t;/td> p; &nbs p; </tr> p; &nbs p; </table>
if (isset($HTTP_GET_VARS['ac
// Captcha check
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
$name = tep_db_prepare_input($HTTP_POS
$email_address = tep_db_prepare_input($HTTP_POS
/> $enquiry = tep_db_prepare_input($HTTP_POS
if (tep_validate_email($email_add
&nbs
&nbs
&nbs
&nbs
}
}
$breadcrumb->add(NAVBAR_TIT
?>
-------------- and look for
<tr>
&nbs
&nbs
&nbs
&nbs
<img src="image.php" width="60" height="20" alt="Please enter the values from this image" />
<!-- ------------------------------
&nbs
&nbs
&nbs
&nbs
&nbs