一个简单的PHP图片验证码验证功能
时间:2007-03-29
来源:互联网
代码一:
复制PHP内容到剪贴板
* Filename: yanzheng.php
* Author:心跳BOY(朝)
* Date: 2007-03-29
* @Copyleft SOVO-东软创世公司
*/
<?php
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);
session_start();
$_SESSION['authnum']="";
$im = imagecreate(62,20);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,0,0,$gray);
while(($authnum=rand()%100000)<10000);
$_SESSION['authnum']=$authnum;
imagestring($im, 5, 10, 3, $authnum, $black);
for($i=0;$i<200;$i++)
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
?>
PHP代码:
/** Filename: yanzheng.php
* Author:心跳BOY(朝)
* Date: 2007-03-29
* @Copyleft SOVO-东软创世公司
*/
<?php
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);
session_start();
$_SESSION['authnum']="";
$im = imagecreate(62,20);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,0,0,$gray);
while(($authnum=rand()%100000)<10000);
$_SESSION['authnum']=$authnum;
imagestring($im, 5, 10, 3, $authnum, $black);
for($i=0;$i<200;$i++)
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
?>
复制PHP内容到剪贴板
代码二:
/*
* Filename: index.php
* Author:心跳BOY(朝)
* Date: 2007-03-29
* @Copyleft SOVO-东软创世公司
*/
<form action=authpage.php method=post>
<table>
请输入验证码:<input type=text name=number style="width: 80px"><br>
<input type=submit name="验证" value="提交验证码">
<input type=hidden name=authnum value=<? echo $authnum; ?>>
<img src=yanzheng.php?authnum=<? echo $authnum; ?>>
</table>
</form>
PHP代码:
代码二:
/*
* Filename: index.php
* Author:心跳BOY(朝)
* Date: 2007-03-29
* @Copyleft SOVO-东软创世公司
*/
<form action=authpage.php method=post>
<table>
请输入验证码:<input type=text name=number style="width: 80px"><br>
<input type=submit name="验证" value="提交验证码">
<input type=hidden name=authnum value=<? echo $authnum; ?>>
<img src=yanzheng.php?authnum=<? echo $authnum; ?>>
</table>
</form>
复制PHP内容到剪贴板
<?php
/*
* Filename: authpage.php
* Author:心跳BOY(朝)
* Date: 2007-03-29
* @Copyleft SOVO-东软创世公司
*/
srand((double)microtime()*1000000);
$number=$_POST['number'];
//验证用户输入是否和验证码一致
if(isset($HTTP_SESSION_VARS["authnum"]))
if($number != $HTTP_SESSION_VARS["authnum"] || empty($number)){
echo "校验码不正确!" ;
}else{
echo"验证码通过!";
}
//生成新的四位整数验证码
while(($authnum=rand()%10000)<1000);
?>
PHP代码:
代码三:<?php
/*
* Filename: authpage.php
* Author:心跳BOY(朝)
* Date: 2007-03-29
* @Copyleft SOVO-东软创世公司
*/
srand((double)microtime()*1000000);
$number=$_POST['number'];
//验证用户输入是否和验证码一致
if(isset($HTTP_SESSION_VARS["authnum"]))
if($number != $HTTP_SESSION_VARS["authnum"] || empty($number)){
echo "校验码不正确!" ;
}else{
echo"验证码通过!";
}
//生成新的四位整数验证码
while(($authnum=rand()%10000)<1000);
?>
作者: pat2007 发布时间: 2007-03-29
支持一下,呵呵
作者: 默默 发布时间: 2007-04-04
我试了下 authpage.php 验证是否输入一致这里判断不起作用
为什么?
为什么?
作者: 纯色理想 发布时间: 2007-05-08
刚好用得着 看一下
作者: lovefun 发布时间: 2007-11-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28