<?php
class auth {
private $width; //宽度
private $height; //高度
private $codeNum; //随机数变量
private $checkCode;
private $img;
private $level;
function __construct($width=80,$height=30,$codeNum=4){
$this->width = $width;
$this->height = $height;
$this->codeNum = $codeNum;
$this->checkCode = $this->createCode(); //调用创建数字函数
}
//产生随机数
private function createCode(){
for($i=0;$i<$this->codeNum;$i++){
$rand = rand(1,3);
switch($rand){
case 1:
$asciiNum = rand(48,57);
break;
case 2:
$asciiNum = rand(65,90);
break;
case 3:
$asciiNum = rand(97,122);
break;
}
$ass.=sprintf('%c',$asciiNum);
}
return $ass;
}
function showImg(){
//第一步 产生画布 并为画布添加颜色
$this->createImg();
$this->createMap();
//第二步 定义背景颜色 及 画笔
$this->createBgcolor();
//第三步 产生干扰
//第四步 写字
//第五步 输出
$this->outPutAuth();
//销毁
}
//创建一个真彩图像 imagecreatetruecolor()
private function createImg(){
$this->img = imagecreatetruecolor($this->width,$this->height);
}
//画一个矩形 并填充imagefilledrectangle();
private function createMap(){
imagefilledrectangle($this->img,0,0,80,30,$this->createBgcolor());
}
//为一幅图画分配颜色 imagecolorallocate();
private function createBgcolor(){
return imagecolorallocate($this->img,rand(0,155),rand(120,255),rand(40,105));
}
//imagetypes imagepng查手册
private function outPutAuth(){
if(imagetypes()&IMG_PNG){
imagepng($this->img);
}
}
// function auth() {
// }
}
$newauth = new auth();
$newauth->showImg();
?>