<?php
session_start();$password = my_random_password(5);
$_SESSION["CheckCode"] = $password;
function my_random_password($length)
{
    $result = "";
    $string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
    for ($i = 0 ; $i < $length ; $i++)
    {
        $result .= $string[mt_rand(0 , strlen($string) - 1)];
    }
    return $result;
}header ("content-type: image/gif");
//图像长宽初始化
$image_x = $_GET['width'];
$image_y = $_GET['height'];
//创建图片
$image = imagecreate($image_x , $image_y);
//定义背景色
$background_color = imagecolorallocate($image , 0xFF , 0xFF , 0xFF);
//定义所需要的颜色
$black_color = imagecolorallocate($image, 100, 50, 255);
$gray_color  = imagecolorallocate($image , 0xdd , 0xdd , 0xdd);
//循环生成雪花点
for ($i = 0 ; $i < 1000 ; $i++)
{
    imagesetpixel($image , mt_rand(0 , $image_x) , mt_rand(0 , $image_y) , $gray_color);
}
//把随机字符串输入图片
//imagestring($image, 8, 10, 3, $password, $black_color);
imagettftext($image, 12, 0, 5, 17, $black_color, './ariblk.ttf', $password);
//生成矩形边框
imagerectangle($image , 0 , 0 , $image_x - 1 , $image_y - 1 , $black_color);
//生成图片
imagegif($image);
//释放与$image关联的内存
imagedestroy($image);
?>