寒窗轩,寒川的个人网络博客,记录互联网事,学习网络编程、分享工作经验、人生感悟,包括但不限于程序代码、数据库、Office办公、随笔等内容。

简单的php验证码验证程序

code.php
<?php
//生成验证码图片
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);//播下一个生成随机数字的种子,以方便下面随机数生成的使用
session_start();//将随机数存入session中
$_SESSION['code']="";
$image = imagecreate(55,20); //制定图片背景大小
$black = ImageColorAllocate($image, 0,0,0); //设定三种颜色
$white = ImageColorAllocate($image, 255,255,255);
$gray = ImageColorAllocate($image, 255,255,255);
imagefill($image,0,0,$gray); //采用区域填充法,设定(0,0)
while(($code=rand()%10000)<1000);//设置位数
$_SESSION['code']=$code;
imagestring($image, 5, 10, 3, $code, $black);
ImagePNG($image);
ImageDestroy($image);
?>

test.php
<?php
session_start();
if(!isset($_POST['code']))   $_POST['code']="";
if($_POST['code']=='')
{
?>
<form method="post" action="" name="form">
<input type="text" name="code"><img src="code.php">
<input input type="submit" value=" 登 录"">
</form>
<?php
}
else if ($_POST['code']==$_SESSION['code']) echo '验证码验证成功!'; else print'验证码错误!';
?>

程序 2009-11-04 11:47:58 53 0 8134 php编程
文章写得不错?我是土豪我要在线打赏!
在线打赏

昵称:

验证码:验证码

评论:

文章分类
系统
程序
数据
Office
随笔
热门文章
VB.net开发的word转pdf的小工具
使用python把word转成pdf
文章推荐
免责声明
关于博主
开篇第一章
随机推荐
kindeditor编辑器测试
一个24点的C程序
word的表格后面总是有一页空白页怎么办?
如何在HTML文件中嵌入另一文件内容(*.htm , *.txt),非Iframe
Google Font API打造美轮美奂的网页字体
pdf、word、txt、excel等文档转flash(swf)软件—虚拟打印机FlashPaper
地震,太恐怖了
二级是狗屎
本站有自己的域名了
摸死你个性签名集合
友情连接
春燕网络
谢润的博客
企安文库