代码一:
/*
* 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);
?>
* 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);
?>
代码二:
/*
* 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>
* 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: 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);
?>
/*
* 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);
?>