<?php
error_reporting(E_ALL & ~E_NOTICE);
session_start();
header("Content-type: image/jpeg");
//if (isset($_SESSION["SecurityCode"]) && $_SESSION["SecurityCode"] != "") {
// $_string = $_SESSION["SecurityCode"];
//} else {
$_string = RndCode();
$_SESSION["SecurityCode"] = strtoupper($_string);
//}
$x=100;
$y=35;
$im=imagecreatetruecolor($x,$y);
$text_color=imagecolorallocate($im, 0, 0, 0);
$bg_color=imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 1, 1, $x-2, $y-2, $bg_color);
$font=realpath("./arial.ttf"); // â íåêîòîðûõ ñëó÷àÿõ ìîæíî óêàçàòü ïðîñòî arial.ttf
mt_srand((double)microtime() * 1000000);
$size=18;
imagettftext($im, $size, 10, 16, 32, $text_color, $font, $_string);
for($i=1;$i<20;$i++){
$px=mt_rand(0,$x);
$py=mt_rand(0,$y);
imageline($im, $px, $py, $px+mt_rand(0,20)-5, $py+mt_rand(0,20)-5, $text_color);
}
imagejpeg($im,'', 80);
imagedestroy($im);
function RndCode() {
$strSymbols = "2345689ERYPADFHKXBNM";
$strRet = "";
$i = 0;
mt_srand((double)microtime() * 1000000);
while ($i < 4)
{
$strRet .= $strSymbols[mt_rand(0, strlen($strSymbols) - 1)];
$i++;
}
return $strRet;
}
?>