PHP验证码绘制

验证码文件checkCode.php 
<?php

   //使用php绘图技术,画出自己的验证码

   $checkCode="";

   for ($i=0;$i<4;$i++){

    $checkCode.=dechex(rand(1,15));

   }
   //创建画布

   $images1= imagecreatetruecolor(110,30);

   //开启Session

   session_start();

   $_SESSION['checkcode']=$checkCode;

   $color=imagecolorallocate($images1,255,255,255);

   //画出干扰线

   for ($i=0;$i<11;$i++){

    imageline($images1,rand(0,110),rand(0,30),rand(0,110),rand(0,30),imagecolorallocate($images1,rand(0,255),rand(0,255),rand(0,255)));

   }

    imagestring($images1,rand(1,5),rand(0,80),rand(0,23),$checkCode,$color); 

    header("content-type:image/png");

    imagepng($images1);

    imagedestroy($images1);
?> 
 输出验证码文件
<!DOCTYPE img PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd
">

<html>

  <head><meta http-equiv="content-type" content="text/html;charset=utf-8"/></head>

  <body>

  请输入验证码:<img src="checkcode.php" onclick="this.src='checkcode.php?ll='+Math.random()"/>;

</body>

</html>

你可能感兴趣的:(PHP验证码绘制)