PHP验证码类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
<?php /** * 验证码类 * @author LiZeQiao <674531003@qq.com> * @version */ //验证码类 class Verify{ //属性 public $img; public $w; public $h; public $num; public $code; public $bgcolor; public $fcolor; function __construct($w,$h,$num){ $this->w=$w; $this->h=$h; $this->num=$num; } //1、创建画布 function create(){ $this->img=imagecreate($this->w,$this->h); } //2、准备颜色 function color(){ $this->bgcolor=imagecolorallocate($this->img,0,0,0); $this->fcolor=imagecolorallocate($this->img,0,255,0); } //3、填充画布颜色 function imgfill(){ imagefill($this->img,0,0,$this->bgcolor); } //4、准备验证字符串 function code(){ session_start(); $str="1234567890"; $this->code=substr(str_shuffle($str),0,$this->num); $_SESSION['code']=$this->code; $fontsize=rand(3,5); for($i=0;$i<$this->num;$i++){ $x=floor($this->w/$this->num)*$i+3; $y=rand(0,$this->h-imagefontheight($fontsize)); imagestring($this->img,$fontsize,$x,$y,$this->code{$i},$this->fcolor); } } //5、输出图片 function imgout(){ header("content-type:image/jpeg"); imagejpeg($this->img); } //6、销毁资源 function __destruct(){ imagedestroy($this->img); } //7、display方法调用所有的方法 function display(){ $this->create(); $this->color(); $this->imgfill(); $this->code(); $this->imgout(); } } $img=new Verify(50,30,4); $img->display(); ?> |
- PHP分页类
- 网络术语概念