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

PHP
真正面向对象编程:PHP5.01发布
Zend公司全球首推PHP认证
使用MaxMind 根据IP地址对访问者定位
动态网站web开发 PHP、ASP还是ASP.NET
PHP5.0正式发布 不完全兼容PHP4 新增多项功能
PHP的一个完整SMTP类(解决邮件服务器需要验证时的问题)
提升PHP执行速度全攻略(上)
两种php调用Java对象的方法
PHP开发文件系统实例讲解
如何使用动态共享对象的模式来安装PHP
PHP编程网上资源导航
PHP安全编程之加密功能
PHP使用者状态管理功能的应用
用IE远程创建Mysql数据库的简易程序
phpBB BBcode处理的漏洞
一个目录遍历函数
生成缩略图
模拟xcopy的函数
PHP 中执行系统外部命令
PHP输出控制功能在简繁体转换中的应用

PHP 中的 图形数字验证代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 46 ::
收藏到网摘: 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);