View file znak/captcha.php

File size: 1.24Kb
<?php
session_start();

$code = mt_rand(1111, 9999);
$_SESSION['captcha'] = $code;

$code1 = substr($code, 0, 1);
$code2 = substr($code, 1, 1);
$code3 = substr($code, 2, 1);
$code4 = substr($code, 3, 1);

$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), $code1, $color1);
imagestring($img, 5, mt_rand(11,12), mt_rand(0,3), $code2, $color2);
imagestring($img, 5, mt_rand(20,21), mt_rand(0,3), $code3, $color2);
imagestring($img, 5, mt_rand(29,30), mt_rand(0,3), $code4, $color3);

for($i = 0; $i < 5; $i++)
{
$temp_color = imagecolorallocate($img, 204, 204, 204);
$pos = array(mt_rand(0,42), mt_rand(0,18), mt_rand(0,42), mt_rand(0,18));

imageline($img, $pos[0], $pos[1], $pos[2], $pos[3], $temp_color);
}

header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
exit();
?>