PHP 实现图片验证码
来源:互联网 发布:java房屋租赁系统论文 编辑:程序博客网 时间:2024/06/14 21:28
PHP 实现图片验证码
步骤
产生随机字符串
创建一张简单的图片,设置背景色,文本色
再加一些干扰线,干扰素
输出图像
销毁图像资源
<?php//PHP生成图片验证码class VerifyImage{ private $verifyCode; private $image; //生成随机字串 private function createCode($type=1,$length=4){ if ($type == 1) { $verifyCode = implode('', range(0, 9)); }elseif ($type == 2) { $verifyCode = implode('', array_merge(range('a', 'z'),range('A', 'Z'))); }else{ $verifyCode = implode('', array_merge(range('a', 'z'),range(0, 9),range('A', 'Z'))); } //判断生成字符是否符合要求 if (strlen($verifyCode)<$length) { return false; } //打乱字符串 $verifyCode = str_shuffle($verifyCode); return substr($verifyCode, 0,$length); } //生成图片,并加入干扰线,干扰素 public function createImage($type=1,$length=4,$width = 80,$height = 40){ $verifyCode = $this->createCode($type,$length); $image = imagecreatetruecolor($width, $height); //白色背景 $white = imagecolorallocate($image, 255, 255, 255); //字体颜色 $fontStyle = imagecolorallocate($image, rand(0, 255),rand(0, 255), rand(0, 255));; imagefill($image, 0, 0, $white); imagestring($image, 5, 10, 10, $verifyCode, $fontStyle); //加入干扰点 for($i = 0; $i < 80; $i++) { $color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255)); imagesetpixel($image, rand(0, $width), rand(0,$height), $color); } //干扰线 for($i = 0; $i < 5; $i++) { $color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255)); imageline($image, rand(0, $width), rand(0, $height), rand(0, $width), rand(0, $height), $color); } //输出图片 header("Content-type: image/png"); imagepng($image); //释放资源 imagedestroy($image); }}$im = new VerifyImage();;$im->createImage(3);?>
0 0
- PHP实现图片验证码
- PHP实现验证码图片
- 【PHP】实现验证码图片
- PHP 实现图片验证码
- php中实现图片验证码
- PHP图片验证码的实现
- PHP图片验证码
- php 图片验证码
- php 图片验证码
- php图片验证码
- 【PHP】图片验证码
- php 图片验证码
- php验证码--图片
- php 图片验证码
- PHP图片验证码的实现-包括前后台页面
- PHP图片验证码的实现-包括前后台页面
- PHP实现生成GIF动态验证码图片功能
- 【代码】PHP 生成GIF动画实现动态图片验证码
- springmvc中如何配置拦截器
- Java-String、StringBuffer、StringBuilder、StringTokenizer区别
- Bored Three-God
- 实习生网面编程题
- Linux服务器启动Tomcat7报Error listenerStart
- PHP 实现图片验证码
- Python小项目——图片素材下载器
- MessageDigest类MD5加密
- 开博了,记录成长
- Linux下命令行设置IP、网关和DNS
- .NET WEB后端POST和GET请求
- Sturts2中action各项配置的默认值
- 删除Unix服务器某个目录下所有文件
- js匿名函数括号的作用