php:自己设计的一个php验证码
2012-06-21 21:09
246 查看
<?php $length=5; //即5个字符 $length_x=$length; while($length-->0){ $temp=rand(1,3); switch($temp){ case 1: $chars[]=sprintf("%c",rand(65,90)); break; case 2: $chars[]=sprintf("%c",rand(97,122)); break; case 3: $chars[]=sprintf("%c",rand(48,57)); break; } } $str=''; foreach($chars as $v){ $str.=$v; } setcookie('checkcode',$str); $img = imagecreatetruecolor(count($chars)*9+18+($length_x-1)*10, 40);//9 $gray = imagecolorallocate($img, 0xC0,0xC0,0xC0); $dark_gray = imagecolorallocate($img, 0xAA,0xAA,0xAA); $bgcolor = imagecolorallocate($img, rand(0,255),rand(0,255),rand(0,255)); imagefill($img, 0, 0, $bgcolor); $x=9; for($i=0;$i<count($chars);$i++){ // $fontColor = imagecolorallocate($img, rand(0,255),rand(0,255),rand(0,255)); imagechar($img, 5, $x, rand(0,25), $chars[$i], $fontColor); $x+=9+10; } //imageString($img, 5, 2, 3, 'hello world', $gray); header("Content-type: image/png"); imagepng($img); //6-20.php ?>
<html> <head> <title>1</title> <style type='text/css'> </style> </head> <body> <form action='' method='get'> <input type='text' name='checkcode'/> <img src='6-20.php' onclick="this.src='6-20.php?tmp='+Math.random();" style='cursor:pointer;'/> <input type='submit' value='提交'/> </form> <?php if($_GET){ if($_COOKIE['checkcode']==$_GET['checkcode']) echo " <font color='green'>验证码正确!{$_GET[checkcode]}</font>"; else echo " <font color='red'>验证码错误!</font>"; } //6-21.php ?> </body> </html>
相关文章推荐
- 自己设计的一个PHP的MVC framework
- 12306验证码太难,试着用php自己做一个验证码吧!
- 模仿了一个夸张的商品倒计时效果,设计的精简当然也很丑,只是为了检测自己说明问题
- php 自己写的一个数组分类合并array_merge(函数的剖析)
- 利用 Composer 一步一步构建自己的 PHP 框架(三)——设计 MVC
- PHP 验证码不显示只有一个小红叉的解决方法
- 一个社群线下聚会方案让每个城市都有自己的组织是如何设计的?
- 一个真正符合中国国情的工作流设计参考(包括PHP实现)
- //4.创建一个数组, //实现函数init()初始化数组、 //实现empty()清空数组、 //实现reverse()函数完成数组元素的逆置。 //要求:自己设计函数的参数,返回值。
- day19字符流的缓冲区。自己MyBufferReader的readLine方法。装饰设计模式。字节流。自定义一个缓冲区模拟BufferedInputStream。读取键盘
- PHP一个漂亮的验证码
- 教大家如何设计实现自己的PHP短网址服务
- 一个简单的php图形验证码生成程序
- 自己设计了一个wipebox 幻灯片
- 心得9--三步教你自己一个验证码工具
- PHP碎码——自己写的验证码
- 一个简单的php图形验证码生成程序
- 模块化思想:创建一个数组, 实现函数init()初始化数组、 实现empty()清空数组、 实现reverse()函数完成数组元素的逆置。 要求:自己设计函数的参数,返回值。
- IOS 自己设计的一个APP,附源码
- 自己实现一个验证码功能