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

Размер файла: 1.53Kb
<?php
$randC = array(1 => mt_rand(0,9), 2 => mt_rand(0,9), 3 => mt_rand(0,9), 4 => mt_rand(0,9));
$openImg = imagecreate(51, 17);
$fontUrl = 'system/comicbd.ttf';

$cookie_url = $_SERVER['SERVER_NAME'];
setcookie('code',$randC[1].$randC[2].$randC[3].$randC[4], time() + 31536000, "/", $cookie_url);
$_SESSION['code'] = $randC[1].$randC[2].$randC[3].$randC[4];

imagecolorallocate($openImg, 255, 255, 255);

for ($i = 0; $i < 5; $i++) {
  $colorLine = imagecolorallocate($openImg, mt_rand(150,250), mt_rand(150,250), mt_rand(150,250));
  imageline($openImg, rand(2,49), rand(2,14), rand(2,49), rand(2,14), $colorLine);
}

$textC1	= imagecolorallocate($openImg, mt_rand(30,100), mt_rand(80,150), mt_rand(100,155));
$textC2 = imagecolorallocate($openImg, mt_rand(30,100), mt_rand(80,150), mt_rand(100,155));
$textC3	= imagecolorallocate($openImg, mt_rand(30,100), mt_rand(80,150), mt_rand(100,155));
$textC4	= imagecolorallocate($openImg, mt_rand(30,100), mt_rand(80,150), mt_rand(100,155));

imagettftext($openImg, mt_rand(11,14), mt_rand(3,7), mt_rand(5,10), mt_rand(14,16),  $textC1, $fontUrl, $randC[1]);
imagettftext($openImg, mt_rand(11,14), mt_rand(3,7), mt_rand(16,20), mt_rand(14,16),  $textC2, $fontUrl, $randC[2]);
imagettftext($openImg, mt_rand(11,14), mt_rand(3,7), mt_rand(26,30), mt_rand(14,16),  $textC3, $fontUrl, $randC[3]);
imagettftext($openImg, mt_rand(11,14), mt_rand(3,7), mt_rand(35,40), mt_rand(14,16),  $textC4, $fontUrl, $randC[4]);

header('Content-type: image/gif');
imagegif($openImg);
imagedestroy($openImg);
?>