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

PHP
实现树状结构的两种方法
PHP4(windows版本)中的COM函数
多文件上传的例子
PHP中的超全局变量
PHP树的代码,可以嵌套任意层
强烈推荐:php.ini中文版(1)
强烈推荐:php.ini中文版(2)
国内php原创论坛
PHP&MYSQL服务器配置说明
Apache设置虚拟WEB
提升PHP执行速度全攻略
Mysql的常用命令
用Apache反向代理设置对外的WWW和文件服务器
php.ini中文版
ASP知识讲座四
一个用于MySQL的PHP XML类
phpmyadmin操作流程
PHP4中实现动态代理
把PHP安装为Apache DSO
正则表达式语法

PHP 中的 图形数字验证代码


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