PDA

View Full Version : مشکل در captcha



majid534
دوشنبه 20 آذر 1391, 15:25 عصر
سلام ...
من با استفاده از متد زیر captcha رو در سایت قالب پیاده کردم اما ظاهرا ی مشکلی هست چون عکس رو نمیسازه ( ب جای عکس value نمایش داده میشه ... )

captcha.php :

<?php
$font='fonts/Disney.ttf';
$count=40; // تعداد خط ها
$fSize=40; // اندازه فونت
$height=50; // ارتفاع عکس
$width=150; // عرض عکس
$img=imagecreate($width,$height) or die("You should install GD first!!");
$backColor=imagecolorallocate($img,255,255,255);// رنگ پشت عکس
$lineColor=imagecolorallocate($img,255,238,238);// رنگ خط ها
$textColor=imagecolorallocate($img,0,238,255);// رنگ نوشته
$string="abcdefghijklmnopqrstuvwxyz0123456789";
$str='';
for($i=0;$i<6;$i++){
$char=rand(0,36);
$str.=$string{$char};
}
$textbox=imagettfbbox($fSize,0,$font,$str) or die('Error in imagettfbbox function or font!!');
$x=($width-$textbox[4])/2;
$y=($height-$textbox[5])/2;
imagettftext($img,$fSize,0,$x,$y,$textColor,$font, $str) or die('Error in imagettftext function!!');
for($i=0;$i<$count;$i++){
$x1=rand(0,$width);$x2=rand(0,$width);
$y1=rand(0,$width);$y2=rand(0,$width);
imageline($img,$x1,$y1,$x2,$y2,$lineColor);
}
header('Content-Type: image/jpeg');
imagejpeg($img,NULL,100);
imagedestroy($img);
session_start();
$_SESSION['img_text']=$str;

index.php:

<img alt="Captcha" src="captcha.php" /> <input type="text" name="captcha" />

process.php :

<?php
session_start();
if($_SESSION['img_text']!=$_POST['captcha']){
die('Error in inserted Captcha!!');
}else{
// ... OK, continue!!
}

با تشکر