php是有GD生成验证码

html代码

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
<!--
 * Created on 2015-5-22
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
-->
 <head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  <title> </title>
 </head>
 <body>
  <form action="check.php" name="form1" method="post">
  <table>
  <tr>
  <td>验证码:<input type="text" name="chkcode" value="" size="15" maxlength="4"></td>
  <td><iframe src="crecode.php" height="50px" width="80px" frameborder="0" id="chkimg"></iframe>
  <input type="button" value="看不清,换一张" onclick="chkimg.location.reload();">
  </td>
  </tr>
  </table>
  <input type="hidden" value="4" name="checkcnt"/>
  <input type="submit" name="submit1" value="提交"/>
  </form>
 </body>
</html>

########################################################################################

生成验证码图像的代码(crecode.php)

#######################################################################################

<?php
/*
 * Created on 2015-5-22
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 header("Content-type:image/png");
 session_start();
 $authnum="";
 $str="abcdefghijkmnopqrstuvwxyz1234567890";
 $strLength=strlen($str);
 for($i=1;$i<=4;$i++){
  $num=rand(0,$strLength-1);
  $authnum .=$str[$num];
 }
 
 $_SESSION["authnum"]=$authnum;
 srand((double)microtime()*1000000);
 $im=imagecreate(50,20);
 
 $gray=imagecolorallocate($im,200,200,100);
 $white=imagecolorallocate($im,255,255,255);
 
 imagefill($im,10,5,$gray);
 $li=imagecolorallocate($im,150,150,150);
 for($i=0;$i<3;$i++){
  imageline($im,rand(0,20),rand(0,50),rand(20,40),rand(0,50),$li);
 }
 
 for($i=0;$i<strlen($_SESSION['authnum']);$i++){
  $strColor=imagecolorallocate($im,mt_rand(0,100),mt_rand(50,150),mt_rand(100,200));
  $fontSize=mt_rand(3,5);
  $x=mt_rand(1,5)+50*$i/4;
  $y=mt_rand(1,5);
  imagestring($im,$fontSize,$x,$y,$_SESSION['authnum'][$i],$strColor);
 }
 for($i=0;$i<90;$i++){
  imagesetpixel($im,rand()%70,rand()%30,$gray);
 }
 imagepng($im);
 imagedestroy($im);
?>

##########################################################

验证验证码

#########################################################

<?php
/*
 * Created on 2015-5-22
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 header("Content-type:text/html;charset=utf-8");
 session_start();
 $chkCode=strtoupper($_POST['chkcode']);
 $auth=strtoupper($_SESSION['authnum']);
 
//echo $chkCode;
//echo "<br>";
// echo $_SESSION['authnum'];
 if($chkCode==$auth){
echo "验证成功!";
 
}else{
  echo "验证失败!";
 
 }
 session_destroy();
?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值