Codice PHP:
<?php
session_start();
error_reporting(E_ALL);
# creo l'immagine #
$img=ImageCreateTrueColor(140,50);
# imposto gli headers #
header("Content-type: image/png");
# stampo sullo sfondo 100 eclissi con colori opachi #
for ($i=1;$i<100;$i++) {
$rgb1_ell=rand(0,100);
$rgb2_ell=rand(0,100);
$rgb3_ell=rand(0,100);
$trasparenza_ell=rand(30,90);
$color_ell=ImageColorResolveAlpha($img,$rgb1_ell,$rgb2_ell,$rgb3_ell,$trasparenza_ell);
$x_ell=rand(0,150);
$y_ell=rand(0,50);
$width_ell=rand(5,20);
$height_ell=rand(5,20);
ImageFilledEllipse($img,$x_ell,$y_ell,$width_ell,$height_ell,$color_ell);
}
# 1° carattere #
$car1=array('1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F','G','H','I','L','M','N','O','P','Q','R','S','T','U','V','Z','K','J','Y','W','X');
$angle1=rand(0,20);
$rgb1_1=rand(150,255);
$rgb2_1=rand(150,255);
$rgb3_1=rand(150,255);
$color_str1=imageColorResolveAlpha($img,$rgb1_1,$rgb2_1,$rgb3_1,0);
$asd1=rand(0,35);
$str1=$car1[$asd1];
ImageTTFText($img,20,$angle1,15,25,$color_str1,'times.TTF',$str1);
# 2° carattere #
$car2=array('1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F','G','H','I','L','M','N','O','P','Q','R','S','T','U','V','Z','K','J','Y','W','X');
$angle2=rand(0,20);
$rgb1_2=rand(150,255);
$rgb2_2=rand(150,255);
$rgb3_2=rand(150,255);
$color_str2=imageColorResolveAlpha($img,$rgb1_2,$rgb2_2,$rgb3_2,0);
$asd2=rand(0,35);
$str2=$car2[$asd2];
ImageTTFText($img,20,$angle2,40,35,$color_str2,'times.TTF',$str2);
# 3° carattere #
$car3=array('1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F','G','H','I','L','M','N','O','P','Q','R','S','T','U','V','Z','K','J','Y','W','X');
$angle3=rand(0,20);
$rgb1_3=rand(150,255);
$rgb2_3=rand(150,255);
$rgb3_3=rand(150,255);
$color_str3=imageColorResolveAlpha($img,$rgb1_3,$rgb2_3,$rgb3_3,0);
$asd3=rand(0,35);
$str3=$car3[$asd3];
ImageTTFText($img,20,$angle3,65,20,$color_str3,'times.TTF',$str3);
# 4° carattere #
$car4=array('1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F','G','H','I','L','M','N','O','P','Q','R','S','T','U','V','Z','K','J','Y','W','X');
$angle4=rand(0,20);
$rgb1_4=rand(150,255);
$rgb2_4=rand(150,255);
$rgb3_4=rand(150,255);
$color_str4=imageColorResolveAlpha($img,$rgb1_4,$rgb2_4,$rgb3_4,0);
$asd4=rand(0,35);
$str4=$car4[$asd4];
ImageTTFText($img,20,$angle4,85,39,$color_str4,'times.TTF',$str4);
# 5° carattere #
$car5=array('1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F','G','H','I','L','M','N','O','P','Q','R','S','T','U','V','Z','K','J','Y','W','X');
$angle5=rand(0,20);
$rgb1_5=rand(150,255);
$rgb2_5=rand(150,255);
$rgb3_5=rand(150,255);
$color_str5=imageColorResolveAlpha($img,$rgb1_5,$rgb2_5,$rgb3_5,0);
$asd5=rand(0,35);
$str5=$car5[$asd5];
ImageTTFText($img,20,$angle5,115,23,$color_str5,'times.TTF',$str5);
$stringa= $str1 . $str2 . $str3 . $str4 . $str5;
$_SESSION['captcha'] = $stringa;
# l'immagine PNG #
ImagePng($img);
# ed infine la distruggo #
ImageDestroy($img);
?>
è un po' rudimentale.. :P non ho usato il ciclo for per poi concatenare i 5 caratteri e passarli con una sessione... però a pensnadoci mi è venuto in mente un modo di farlo anche con il for.. :P vabbè.. :D se mi aiutaste a capire perché in locale va e qui no ve ne sarei grato.. :)