Hey everyone, I’ve followed some tutorials and created my own CAPTCHA script. The problem with my script is that, for some reason, the SESSION variable string is always different from the string that is displayed in the image, meaning that the form will never validate. What is wrong with this code? If I echo $_SESSION[‘captcha’] and $
Actual file:
[code=php]<?
session_start();
include(“/home/tusserte/library/includes/headerhtml.php”);
include(“/home/tusserte/library/validate.php”);
if(!$validform) {
include(“/home/tusserte/library/includes/signupform.php”);
}
include(“/home/tusserte/library/includes/footerhtml.php”);
?>
Important part of signupform.php:
[code=html]<td colspan=”3″>
<img src=”http://www.thebiasphere.org/captcha.php” alt=”Type the text you see in this image” />
</td>
</tr>
<tr>
<td>
Type the 6 character code in the image above:
</td>
<td colspan=”2″ class=”input”>
<input type=”text” name=”captcha” id=”captcha” />
</td>
captcha.php file:
[code=php]<?
session_start();
header(“Content-type: image/jpeg”);
header(“Cache-Control: no-cache, must-revalidate”);
function create_font_image($size, $angle, $font, $char) {
$bx=mt_rand(10,20);
$by=mt_rand(60,70);
$bx2=mt_rand(250,280);
$by2=mt_rand(0,75);
$confuse1=substr(md5(time()), 0, 5);
$confuse1size=6;
$bg=mt_rand(1,3);
$bg=”/home/tusserte/library/captchabg”.$bg.”.png”;
$im=imagecreatefrompng($bg);
$i=0;
while ($i<4) {
$x1=mt_rand(0,300);
$x2=mt_rand(0,300);
$colorval=mt_rand(0,255);
$color=imagecolorallocate($im, $colorval, $colorval, $colorval);
imageline($im, $x1, 3, $x2, 72, $color);
$i++;
}
$colorval=mt_rand(0,50);
$color=imagecolorallocate( $im, $colorval, $colorval, $colorval );
imagettftext($im, $size, $angle, $bx, $by, $color, $font, $char);
imagettftext($im, $confuse1size, $angle, $bx2, $by2, $color, $font, $confuse1);
imagefilter($im, IMG_FILTER_EMBOSS);
imagejpeg($im);
imagedestroy($im);
}
$chars= md5(time() * microtime() / date(“myd”));
$chars=substr($chars,1,6);
$_SESSION[‘captcha’]=$chars;
$angle=mt_rand(-3,3);
$size=mt_rand(45,50);
create_font_image($size, $angle, “/home/tusserte/library/BorisBlackBloxx.ttf”, $chars);
?>
The script in action:
[url]http://www.thebiasphere.org/signup.php
The form will send you to a page that simply displays “$_POST[‘captcha’] <hr /> $