Captcha букви и цифри

ExpressYourself

Registered
Можете ли да ми дадете най-елементарната captcha неискам усложнения само да генерира в картинка цифрите и буквите който да са на брой 5 и да ги изкарва на изображение с малки размери 25/25 да кажем :)
 
Ето ти една проста - има пример, динамично определяш колко да е голяма, колко символа и т.н.

http://web-tourist.net/userfiles/2/2201.zip
 
captcha.php
<?php
header("Content-type: image/gif");
$color = "FF7700"; //background
$textcolor = "000000"; // color text
$rand = rand();
$md5 = md5("$rand");
$string = substr("$md5", 0, 5);
setcookie("captcha",$string,time()+3600,"/");
$R = hexdec(substr("$color",0,2));
$G = hexdec(substr("$color",2,2));
$B = hexdec(substr("$color",4,2));
$Rt = hexdec(substr("$textcolor",0,2));
$Gt = hexdec(substr("$textcolor",2,2));
$Bt = hexdec(substr("$textcolor",4,2));
$im = imagecreate(88, 31);
$background_color = imagecolorallocate($im, $R, $G, $B);
$textcolor = imagecolorallocate($im,$Rt,$Gt,$Bt);
Imagestring($im,5,20,5,$string,$textcolor);
imagejpeg($im);
imagedestroy($im);
?>
Ето. Има си обяснения. Малко са но това само трябва да пипаш. Само където ще го извеждаш пишеш <img src="captcha.php">
 
slideR каза:
captcha.php
<?php
header("Content-type: image/gif");
$color = "FF7700"; //background
$textcolor = "000000"; // color text
$rand = rand();
$md5 = md5("$rand");
$string = substr("$md5", 0, 5);
setcookie("captcha",$string,time()+3600,"/");
$R = hexdec(substr("$color",0,2));
$G = hexdec(substr("$color",2,2));
$B = hexdec(substr("$color",4,2));
$Rt = hexdec(substr("$textcolor",0,2));
$Gt = hexdec(substr("$textcolor",2,2));
$Bt = hexdec(substr("$textcolor",4,2));
$im = imagecreate(88, 31);
$background_color = imagecolorallocate($im, $R, $G, $B);
$textcolor = imagecolorallocate($im,$Rt,$Gt,$Bt);
Imagestring($im,5,20,5,$string,$textcolor);
imagejpeg($im);
imagedestroy($im);
?>
Ето. Има си обяснения. Малко са но това само трябва да пипаш. Само където ще го извеждаш пишеш <img src="captcha.php">

Това ми харесва, но няма ли да е по-добре сесия и ако може цветовете да ги настройш на background- #313131; text- #ffffff; че нещо не ми се получава
 
<?php
header("Content-type: image/gif");
$color = "313131"; //background
$textcolor = "FFFFFF"; // color text
$rand = rand();
$md5 = md5("$rand");
$string = substr("$md5", 0, 5);
setcookie("captcha",$string,time()+3600,"/");
$R = hexdec(substr("$color",0,2));
$G = hexdec(substr("$color",2,2));
$B = hexdec(substr("$color",4,2));
$Rt = hexdec(substr("$textcolor",0,2));
$Gt = hexdec(substr("$textcolor",2,2));
$Bt = hexdec(substr("$textcolor",4,2));
$im = imagecreate(88, 31);
$background_color = imagecolorallocate($im, $R, $G, $B);
$textcolor = imagecolorallocate($im,$Rt,$Gt,$Bt);
Imagestring($im,5,20,5,$string,$textcolor);
imagejpeg($im);
imagedestroy($im);
?>
 
slideR каза:
<?php
header("Content-type: image/gif");
$color = "313131"; //background
$textcolor = "FFFFFF"; // color text
$rand = rand();
$md5 = md5("$rand");
$string = substr("$md5", 0, 5);
setcookie("captcha",$string,time()+3600,"/");
$R = hexdec(substr("$color",0,2));
$G = hexdec(substr("$color",2,2));
$B = hexdec(substr("$color",4,2));
$Rt = hexdec(substr("$textcolor",0,2));
$Gt = hexdec(substr("$textcolor",2,2));
$Bt = hexdec(substr("$textcolor",4,2));
$im = imagecreate(88, 31);
$background_color = imagecolorallocate($im, $R, $G, $B);
$textcolor = imagecolorallocate($im,$Rt,$Gt,$Bt);
Imagestring($im,5,20,5,$string,$textcolor);
imagejpeg($im);
imagedestroy($im);
?>

А само искам последно да питам няма ли да е по-добре със сесия отколкото с бисквитка ?
 
Кукито може да се манипулира по - лесно отколкото сесията, защото бисквитката е на твоя компютър. По - добре е със сесия и повече Captcha кодове работятя със сесии.
 

Back
Горе