工会web
This commit is contained in:
39
GonghuiWeb/www/js/index.php
Normal file
39
GonghuiWeb/www/js/index.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
class CCheckCodeFile{
|
||||
private $mCheckCodeNum = 4;//验证码位数
|
||||
private $mCheckCode = '0123456789';//产生的验证码
|
||||
private $mCheckImageWidth = '65';//验证码的图片宽度
|
||||
private $mCheckImageHeight = '20';//验证码的图片宽度
|
||||
//输出验证码图片
|
||||
public function OutCheckImage(){
|
||||
header("Content-type:image/png");//输出图象头信息
|
||||
$im = imagecreate($this->mCheckImageWidth,$this->mCheckImageHeight);//建立图象
|
||||
$black = imagecolorallocate($im,255,255,255);//建立黑色标志符
|
||||
$white = imagecolorallocate($im,0,0,0);//建立白色标志符
|
||||
$gray = imagecolorallocate($im,100,100,100);//建立灰色标志符
|
||||
imagefill($im,80,30,$black);//填充图象
|
||||
for($i=0;$i<50;$i++){
|
||||
$randcolor=imagecolorallocate($im,rand(100,255),rand(100,255),rand(100,255));//建立一个随机图象颜色标志符
|
||||
imagesetpixel($im, rand(0,$this->mCheckImageWidth),rand(0,$this->mCheckImageHeight),$randcolor);//用上一行建立的标志符描点,点的坐标为随机
|
||||
}
|
||||
// for($i=0;$i<5;$i++){
|
||||
// imageline($im,rand(0,$this->mCheckImageWidth),rand(0,$this->mCheckImageHeight),rand(0,$this->mCheckImageWidth),rand(0,$this->mCheckImageHeight),$gray);//以随机坐标画线
|
||||
// }
|
||||
for($i=0;$i<=$this->mCheckCodeNum;$i++){
|
||||
$authnum.=substr($this->mCheckCode,rand(0,9),1);//建立验证字符串
|
||||
}
|
||||
$_SESSION['num']=strtolower($authnum);//把字符串写入SESSION以待验证
|
||||
$x=rand(2,20);
|
||||
$y=rand(2,6);
|
||||
imagestring($im,5,$x,$y,$authnum,$white);//把字符串写入图片
|
||||
imagepng($im);//输出图片
|
||||
imagedestroy($im);//注销图片资源
|
||||
}
|
||||
}
|
||||
session_start();
|
||||
if($_SESSION['num']){
|
||||
unset($_SESSION['num']);//注销上一次的图片验证码
|
||||
}
|
||||
$code_image = new CCheckCodeFile;
|
||||
$code_image ->OutCheckImage();
|
||||
?>
|
||||
Reference in New Issue
Block a user