欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 编程语言 > php >内容正文

php

php 验证码   高洛峰 细说php -凯发k8官方网

发布时间:2025/1/21 php 19 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 php 验证码   高洛峰 细说php 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

前端页面index.php

';}else{echo '输入不对
';} } ?> 用户名:
标题:
内容:
验证码:

生成验证码图片test.php

getcode();//将验证码的图片输出$vcode->outimg();//调用方法

验证码类 print.php

width        =   $width;$this->heigth       =   $height;$this->num          =   $num;$this->code        =   $this->createcode();}//获取字符的验证码function getcode(){return $this->code;}//输出验证码图形function outimg(){//创建背景 颜色 大小 边框$this->createback();           //画字 大小 字体颜色$this->outstring();//干扰元素 点 线条$this->setdisturb();//输出图像$this->printimg();}//创建背景private function createback(){//创建资源$this->img = p_w_picpathcreatetruecolor($this->width, $this->heigth);//设置随机背景颜色$bgcolor = p_w_picpathcolorallocate($this->img, rand(225, 255), rand(225, 255), rand(225, 255));//填充背景色p_w_picpathfill($this->img, 0, 0, $bgcolor);//画矩形$bordercolor = p_w_picpathcolorallocate($this->img, 0, 0, 0);p_w_picpathrectangle($this->img, 0, 0, $this->width-1, $this->heigth-1, $bordercolor);}//画字private function  outstring(){for($i=0;$i<$this->num;$i ){                        $color  =   p_w_picpathcolorallocate($this->img, rand(0, 128), rand(0, 128), rand(0, 128));$font = rand(3,5);$x = 3   ($this->width/$this->num)*$i;$y = rand(1, 5);p_w_picpathstring($this->img, $font,$x, $y, $this->code{$i}, $color);}}//设置干扰元素private function setdisturb(){//加上点数for($i=0;$i<100;$i ){$color  =   p_w_picpathcolorallocate($this->img, rand(0, 255), rand(0, 255), rand(0, 255));p_w_picpathsetpixel($this->img, rand(1, $this->width-2), rand(1, $this->heigth-2), $color);}//加上线条for($i=0;$i<10;$i ){$color  =   p_w_picpathcolorallocate($this->img, rand(0, 255), rand(0, 128), rand(0, 255));p_w_picpatharc($this->img, rand(-10, $this->width 10), rand(-10, $this->heigth 10), rand(30, 300), rand(30, 300), 55, 44, $color);}}//输出图像private function printimg(){//      header("content-type:p_w_picpath/jpeg");//     p_w_picpathjpeg($this->img);if(p_w_picpathtypes() & img_gif){header("content-type:p_w_picpath/gif");p_w_picpathjpeg($this->img);}elseif(p_w_picpathtypes() & img_jpeg){header("content-type:p_w_picpath/jpeg");p_w_picpathjpeg($this->img);}elseif(p_w_picpathtypes() & img_jpg){header("content-type:p_w_picpath/jpg");p_w_picpathjpeg($this->img);}elseif(p_w_picpathtypes() & img_png){header("content-type:p_w_picpath/png");p_w_picpathjpeg($this->img);}}//生成验证码private function  createcode(){$codes = "23456789abcdefghijklmnpqrstuvwxyzabcdefghijklmnpqrstuvwxyz";$code = "";for($i=0;$i<$this->num;$i ){$code .=$codes{rand(0,strlen($codes)-1)};}return $code;}//释放图像资源function __destruct(){p_w_picpathdestroy($this->img);}}



转载于:https://blog.51cto.com/11410485/1842156

总结

以上是凯发k8官方网为你收集整理的php 验证码   高洛峰 细说php的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

网站地图