云中烛火

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

图片文件:a.php

<?php
	$num="";
	
	$num1=rand(0,9);
	$num2=rand(0,9);
	
	$arr=array("+","-","*","/");
	
	$r=rand(0,3);
	
	if($arr[$r]=="+"){
		$result=$num1+$num2;
	}
	else if($arr[$r]=="-"){
		$result=$num1-$num2;
	}
	else if($arr[$r]=="*"){
		$result=$num1*$num2;
	}
	else if($arr[$r]=="/"){
		$num2=rand(1,9);
		$result=$num1/$num2;
	}
	
	$num=$num1.$arr[$r].$num2."=";
	
	/*
	for($i=0;$i<4;$i++){
		$num.=rand(0,9);
	}
	*/
	session_start();
	
	
	
	$_SESSION["checknum"]=$result;
	
	header("Content-type:image/PNG");
	srand((double)microtime()*1000000);
	$im=imagecreate(60,20);
	$black=imageColorAllocate($im,0,0,0);
	$gray=imagecolorallocate($im,200,200,200);
	imagefill($im,0,0,$gray);
	$style=array($black,$black,$black,$black,$black,$gray,$gray,$gray,$gray,$gray);
	imagesetstyle($im,$style);
	$y1=rand(0,20);
	$y2=rand(0,20);
	$y3=rand(0,20);
	$y4=rand(0,20);
	imageline($im,0,$y1,60,$y3,IMG_COLOR_STYLED);
	imageline($im,0,$y2,60,$y4,IMG_COLOR_STYLED);
	for($i=0;$i<80;$i++){
		imagesetpixel($im,rand(0,60),rand(0,20),$black);
	}
	$strx=rand(3,8);

	for($i=0;$i<4;$i++){
		$strpos=rand(1,6);
		imagestring($im,5,$strx,$strpos,substr($num,$i,1),$black);
		$strx+=rand(8,12);
	}
	
	ImagePNG($im);
	ImageDestory($im);
	
?>

 输入验证码页面:b.html

<HTML>
<HEAD>
<TITLE>图形验证码程序</TITLE>
</HEAD>
<BODY>
<form action="c.php" method="post">
<img src="a.php" id="a" onClick="javascript:this.src=this.src+'?rnd=' + Math.random();" alt="" title="看不清,点击刷新"/><br>
请输入验证码:<input type="text" name="passcode">
<input type=submit value="确定">
</form>
</BODY>
</HTML>

 处理验证码页面:c.php

<?php
//验证用户输入的验证码是否正确
session_start();
$passcode=$_SESSION["checknum"];
$usercode=$_POST["passcode"];
if($passcode == $usercode){
 echo "验证码正确!验证通过!";
 }else{
 echo "验证码输入错误!验证失败!";
 }
?>

 

 

source ' E:/a.sql';

posted on 2013-06-23 14:51  云中烛火  阅读(130)  评论(0)    收藏  举报