PHP封装验证码类
来源:互联网 发布:劲舞团做图软件 编辑:程序博客网 时间:2024/06/03 18:57
<?php
class Vercode{
protected $codeNum;
protected $width;
protected $height;
protected $img;
function __construct($width="80",$height="40",$codeNum="4"){
$this->width=$width;
$this->height=$height;
$this->codeNum=$codeNum;
}
protected function createImage(){
$this->img=imagecreatetruecolor($this->width,$this->height);
$color=imagecolorallocate($this->img,rand(100,155),rand(100,155),rand(100,155));
@imagefill($this->img,0,0,$color);
}
protected function random(){
if($this->codeNum<=0){
return false;
}
$str="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
$str=substr(str_shuffle($str),0,$this->codeNum);
return $str;
}
protected function outImg(){
for($i=0;$i<40;$i++){
$linecolor=imagecolorallocate($this->img,rand(100,250),rand(100,250),rand(100,250));
imageline($this->img,rand(0,$this->width-10),rand(0,$this->height-10),rand(0,$this->width),rand($this->width-10,$this->height-10),$linecolor);
}
$strcolor=imagecolorallocate($this->img,250,250,250);
imagestring($this->img,5,rand(10,$this->height-10),rand(10,$this->height-10),$this->random(),$strcolor);
header("Content-type:image/png");
imagepng($this->img);
}
function Imgcode(){
$this->createImage();
$this->outImg();
echo $this->codeNum;
}
function __destruct(){
imagedestroy($this->img);
}
}
$vercode=new Vercode(100,50,6);
$vercode->Imgcode();
?>
class Vercode{
protected $codeNum;
protected $width;
protected $height;
protected $img;
function __construct($width="80",$height="40",$codeNum="4"){
$this->width=$width;
$this->height=$height;
$this->codeNum=$codeNum;
}
protected function createImage(){
$this->img=imagecreatetruecolor($this->width,$this->height);
$color=imagecolorallocate($this->img,rand(100,155),rand(100,155),rand(100,155));
@imagefill($this->img,0,0,$color);
}
protected function random(){
if($this->codeNum<=0){
return false;
}
$str="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
$str=substr(str_shuffle($str),0,$this->codeNum);
return $str;
}
protected function outImg(){
for($i=0;$i<40;$i++){
$linecolor=imagecolorallocate($this->img,rand(100,250),rand(100,250),rand(100,250));
imageline($this->img,rand(0,$this->width-10),rand(0,$this->height-10),rand(0,$this->width),rand($this->width-10,$this->height-10),$linecolor);
}
$strcolor=imagecolorallocate($this->img,250,250,250);
imagestring($this->img,5,rand(10,$this->height-10),rand(10,$this->height-10),$this->random(),$strcolor);
header("Content-type:image/png");
imagepng($this->img);
}
function Imgcode(){
$this->createImage();
$this->outImg();
echo $this->codeNum;
}
function __destruct(){
imagedestroy($this->img);
}
}
$vercode=new Vercode(100,50,6);
$vercode->Imgcode();
?>
0 0
- PHP封装验证码类
- php 验证码封装类
- PHP验证码封装
- php封装生成验证码VerifyImage类
- PHP实现的封装验证码类详解
- php验证码类,phpquery页面解析封装
- 验证码封装类
- 《PHP中产生验证码函数封装》
- php验证码的封装和使用
- php封装一个生成图像验证码
- PHP不会类的同学可以看看,入门级的PHP验证码(未封装)
- 编程的艺术 之 封装一个验证码类(php)
- php验证码实现及使用--封装版
- php验证码类
- php验证码类
- PHP验证码类
- php验证码类
- php 验证码类
- linux 进程内存解析
- 数字图像处理学习笔记:图像保存路径问题
- vb.net 总结
- n a^o7 ! 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛 队友不在,只好划水。。。
- vim编辑显示行号
- PHP封装验证码类
- 一次服务大量超时的java排查过程经验
- 深入浅出UML类图(一)
- leetcode 17 Letter Combinations of a Phone Number
- 树 Path Sum
- 第三章作业 3.24
- Linux内存管理
- android开发之事件处理(祥谈)
- HTTP中GET与POST之间的区别