Просмотр файла gbs/captcha.php

Размер файла: 1.26Kb
<?
session_start();
if(empty($_SESSION['code']))$_SESSION['code']=rand(10000,99999);
$error=!isset($_SESSION['code']);
$font='1.ttf';
$error_str='ОШИБКА';
$img=imagecreatetruecolor(90,25);
imagefill($img,0,0,imagecolorallocate($img,255,255,255));
for($x=rand(0,5);$x<90;$x+=5)for($y=5;$y<90;$y+=5)if(rand(1,100)<25)imagettftext($img,rand(15,30),0,$x,$y,imagecolorallocate($img,$h=rand(225,235),$h,$h),$font,'.');
$cl_line=imagecolorallocate($img,$h=rand(225,235),$h,$h);
$n=rand(0,90);
$wave1=rand(500,560)/100;
$wave2=rand(500,600)/100;
for($i=0;$i<90;$i++){
    $y=sin(deg2rad($i*$wave1+$n))*$wave2+8;
    imageline($img,$i,$y,$i,$y+3,$cl_line);
    imageline($img,$i,$y+8,$i,$y+11,$cl_line);
}
$sizes=array(12,13,14,15,16);
if($error){
     imagettftext($img,15,0,1,20,imagecolorallocate($img,255,0,0),$font,$error_str);
}else{
     $_SESSION['kod']=(string)$_SESSION['code'];

 for($i=0,$x=7;$i<5;$i++,$x+=16){
        imagettftext($img,$error?15:$sizes[$n=array_rand($sizes)],rand(0,1)?rand(-25,-5):rand(5,25),$x,20,$error?imagecolorallocate($img,255,0,0):imagecolorallocate($img,$h=rand(120,150),$h,$h),$font,$error?$error_str[$i]:$_SESSION['kod'][$i]);
        unset($sizes[$n]);
    }
}


header("Content-type: image/png");
imagepng($img);

?>