<?php
header ("Content-type: image/png");
session_start();
session_register('validate');
$_SESSION['validate_code'] = rand(1,9).rand(0,9).rand(0,9).rand(0,9);
//strtoupper(substr(md5(rand()),20,6));
$im = @imagecreate (78, 20);
$background_color = imagecolorallocate ($im,255,255,255);//105 145 184
for ($i=0;$i<=128;$i++){
    $point_color = imagecolorallocate ($im, rand(0,255), rand(0,255), rand(0,255));
    imagesetpixel($im,rand(1,78),rand(1,20),$point_color);
}
for ($i=0;$i<4;$i++){
    $text_color = imagecolorallocate ($im, rand(0,255), rand(0,128), rand(0,255));
    $x = 10 + $i * 17;
    //$x = rand(5,250);
    $y = rand(3,8);
    imagechar($im, 5, $x, $y, $_SESSION['validate_code']{$i}, $text_color);
}
imagepng ($im);
imagedestroy ($im);
?>
