Embed the captcha image by calling a php script in "contact_us.php":
<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 CheckHere'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');
?>











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
Post new comment