span style="color: #0000BB"><?phpclass captcha { //Словарь// private $lib = array('ручка', 'тетрадь'); private $word = null; public $code = null; public function __construct() { $this->word = $this->lib[array_rand($this->lib)]; preg_match_all('/.{1}/u', $this->word, $letters); $letters = $letters[0]; $count = sizeof($letters)-1; $_FL = $letters[0]; $_LL = $letters[$count]; unset($letters[0], $letters[$count]); shuffle($letters); $this->code = $_FL.implode($letters).$_LL; if($this->word == $this->code) self::__construct(); } public function check() { } }$captcha = new captcha;echo $captcha->code;?> |
span style="color: #0000BB"><?php//////////function captcha() { $code = rand(1000,9999); $image = imageCreateTrueColor(40, 20); imageFill($image, 39, 19, imageColorAllocate($image, 128, 128, 128)); imageString($image, 5, 2, 2, $code, imageColorAllocate($image, 0, 0, 0)); imagejpeg($image, 'captcha.jpg', 100); imageDestroy($image); return $code; }//////////session_start();$_SESSION['_CAPTCHA_'] = captcha();?> |
$pkod = str_split(intval($_SESSION['code'])); |
$img = imagecreate(42, 18); |
$fon = imagecolorallocate($img, 255, 255, 255); |
imagefill($img, 0, 0, $fon); |
$color1 = imagecolorallocate($img, mt_rand(0, 204), mt_rand(0, 204), mt_rand(0,204)); |
$color2 = imagecolorallocate($img, mt_rand(0, 204), mt_rand(0, 204), mt_rand(0,204)); |
$color3 = imagecolorallocate($img, mt_rand(0, 204), mt_rand(0, 204), mt_rand(0,204)); |
$color4 = imagecolorallocate($img, mt_rand(0, 204), mt_rand(0, 204), mt_rand(0,204)); |
ImageString($img, 5, mt_rand(2, 3), mt_rand(0, 3), $pkod[0], $color1); |
ImageString($img, 5, mt_rand(11, 12), mt_rand(0, 3), $pkod[1], $color2); |
ImageString($img, 5, mt_rand(20, 21), mt_rand(0, 3), $pkod[2], $color2); |
ImageString($img, 5, mt_rand(29, 30), mt_rand(0, 3), $pkod[3], $color3); |
for($i = 0; $i < 5; $i++){ |
$temp_color = imagecolorallocate($img, mt_rand(155, 204), mt_rand(155, 204),mt_rand(155, 204)); |
imageline($img, mt_rand(0, 42), mt_rand(0, 18), mt_rand(0, 42), mt_rand(0, 18),$temp_color); |
} |
for($i = 0; $i < 50; $i++){ |
$temp_color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); |
imagesetpixel($img, mt_rand(0, 42), mt_rand(0, 18), $temp_color); |
} |
Header('Content-type: image/gif'); |
ImageGIF($img); |
ImageDestroy($img); |
<img src="captcha.php" alt="captcha" /> |
span style="color: #0000BB"><?phpsession_start();$image = imageCreateTrueColor(40, 20);imageFill($image, 39, 19, imageColorAllocate($image, 128, 128, 128));imageString($image, 5, 2, 2, (int)$_SESSION['_CAPTCHA_'], imageColorAllocate($image, 0, 0, 0));header('Content-Type: image/jpeg;');imagejpeg($image, null, 100);imageDestroy($image);?> |