<?php
//高先生简单验证码.
//随机数
//为什么循环0-15的数字
//因为要实现最简单的字母和数字混搭
//16进制0-9 a-f
//dechex 十进制转换为16进制
//创建一个四位的验证码.
//$nmsg. 将每次循环的值累计起来
for($i=0;$i<4;$i++){
$nmsg.= dechex(mt_rand(0,15));
}
//验证码数组准备完成,开始绘图
ob_clean();
//设定标头.告诉浏览器你要生成的MIME类型
header('Content-type:image/png');
//创建一个图形区域.赋值给资源句柄
$im=imagecreatetruecolor(75,25);
//在空白的图像区域绘制填充背景
$blue=imagecolorallocate($im,0,102,255); //颜色1 背景
$white=imagecolorallocate($im,255,255,255); //颜色2 文字
imagefill($im,0,0,$blue); //填充颜色
//生成文本信息.将验证码的字符串写入图片.
imagestring($im,5,18,5,$nmsg,$white);
//输出最终图形
imagepng($im);
//清除占用的资源
imagedestroy($im);
?>