View file captcha.php

File size: 1.92Kb
<?php
# Captcha v1.0 by Wapweb #

$width = 110;
$height =30;
$sign = rand(3,6);
$code = '';
ob_start();
session_start();
error_reporting(E_ALL & ~E_NOTICE);
//$letters = array('a','b','c','d','f','g','h','i','j','k','m','n','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z','2','3','4','5','6','7','8','9');
$letters = range('0','9');
$figures = array('50','70','90','110','130','150','170','190','30');
$img = imagecreatetruecolor($width,$height);
$f1 = rand(220,255);
$f2 = rand(220,255);
$f3 = rand(220,255);
$fon = imagecolorallocate($img , $f1,$f2,$f3);
imagefill($img,0,0,$fon);

/*for ($j=0; $j<$width; $j++) {
    for ($i=0; $i<($height*$width)/100; $i++) {
	$color = imagecolorallocatealpha(
	         $img,
			 $figures[rand(0,count($figures)-1)],
			 $figures[rand(0,count($figures)-1)],
			 $figures[rand(0,count($figures)-1)],
			 rand(10,30));
		imagesetpixel(
		$img,
		rand(0,$width),	
        rand(0,$height),
        $color);		
	}
}*/
for ($j=0; $j<$sign; $j++) {
 imageline($img, 0, rand(0,24), 130, rand(0,40), 0xDCDCDC);
 }
 for ($s=0; $s<80; $s++) {
 imagesetpixel(
		$img,
		rand(0,$width),	
        rand(0,$height),
        $color);	
		}
for ($i=0; $i<$sign; $i++) {
     $h =1;
	 $color =  imagecolorallocatealpha(
	         $img,
			 $figures[rand(0,count($figures)-1)],
			 $figures[rand(0,count($figures)-1)],
			 $figures[rand(0,count($figures)-1)],
			 rand(10,30));
	 
	 $letter = $letters[rand(0,sizeof($letters)-1)];
	 
	 if (empty($x)) $x = $width*0.08;
	 else $x = $x + ($width*0.8)/$sign + rand(0,$width*0.02);
	 if ($h == rand(1,2)) $y = (($height*1)/4) + rand (0,$height*0.1);
	 else $y = (($height*1)/4) - rand(0,$height*0.1);
	 
	 $code.=$letter;
	 if($h == rand(0,1)) $letter = strtoupper($letter);
	 imagestring($img,6,$x,$y,$letter,$color);
}

$_SESSION['code'] = $code;
header("Content-type: image/jpeg");
imagejpeg($img);
ob_end_flush();
?>