当前位置: 首页 > 图文教程 > 网络编程 > PHP > 图形数字验证代码

PHP
PHP中在数据库中保存Checkbox数据(1)
VFP与其他应用程序的集成
用PHP生成自己的LOG文件
用PHP实现文件上传二法
第七节 类的静态成员 [7]
第十三节 对象串行化 [13]
用 php 编写的日历
php+dbfile开发小型留言本
第十四节 命名空间 [14]
第十二节 类的自动加载 [12]
第十一节 重载 [11]
PHP4之真OO
在apache下限制每个虚拟主机的并发数!!!!
跟我学小偷程序之成功偷取首页(第三天)
在PHP中使用XML
使用PHP模拟HTTP认证
一个阿拉伯数字转中文数字的函数
通过对php一些服务器端特性的配置加强php的安全
在Zeus Web Server中安装PHP语言支持
PHP中实现图片的锐化

PHP 中的 图形数字验证代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 50 ::
收藏到网摘: n/a


图形数字验证代码 Code: <?
/*
* Filename: authpage.php
*/

srand((double)microtime()*1000000);

//验证用户输入是否和验证码一致
if(isset($_POST['authinput']))
{

if(strcmp($_POST['authnum'],$_POST['authinput'])==0)
echo "验证成功!";
else
echo "验证失败!";
}

//生成新的四位整数验证码
while(($authnum=rand()%10000)<1000);
?>
<form action=authpage.php method=post>
<table>
请输入验证码:<input type=text name=authinput style="width: 80px"><br>
<input type=submit name="验证" value="提交验证码">
<input type=hidden name=authnum value=<? echo $authnum; ?>>
<img src=authimg.php?authnum=<? echo $authnum; ?>>
</table>
</form>
-------------------------------------------------------------------------------------------------------------
<?
/*
* Filename: authimg.php
*/
//生成验证码图片
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);
$im = imagecreate(58,28);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,68,30,$gray);

//将四位整数验证码绘入图片
imagestring($im, 5, 10, 8, $HTTP_GET_VARS['authnum'], $white);

for($i=0;$i<50;$i++) //加入干扰象素
{
imagesetpixel($im, rand()%70 , rand()%30 , $gray);
}

ImagePNG($im);
ImageDestroy($im);