最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php生成验证码与验证码验证完整实例
时间:2012-02-02 编辑:简简单单 来源:一聚教程网
hyml页面
代码如下 | 复制代码 |
|
verifycode.php文件代码如下
代码如下 | 复制代码 |
/* 图片验证码 Powered By KASON */ session_start(); $num=4;//验证码个数 $width=80;//验证码宽度 $height=20;//验证码高度 $code=' '; for($i=0;$i<$num;$i++)//生成验证码 { switch(rand(0,2)) { case 0:$code[$i]=chr(rand(48,57));break;//数字 case 1:$code[$i]=chr(rand(65,90));break;//大写字母 case 2:$code[$i]=chr(rand(97,122));break;//小写字母 } } $_SESSION["VerifyCode"]=$code; $image=imagecreate($width,$height); imagecolorallocate($image,255,255,255); for($i=0;$i<80;$i++)//生成干扰像素 { $dis_color=imagecolorallocate($image,rand(0,2555),rand(0,255),rand(0,255)); imagesetpixel($image,rand(1,$width),rand(1,$height),$dis_color); } for($i=0;$i<$num;$i++)//打印字符到图像 { $char_color=imagecolorallocate($image,rand(0,2555),rand(0,255),rand(0,255)); imagechar($image,60,($width/$num)*$i,rand(0,5),$code[$i],$char_color); } header("Content-type:image/png"); imagepng($image);//输出图像到浏览器 imagedestroy($image);//释放资源 ?> |
checkcode.php文件如下
代码如下 | 复制代码 |
|
-
上一个: 完美的php防sql注入代码
-
下一个: php开发中常用的技巧分享
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24