php 验证码

来源:互联网 发布:silhouette软件 编辑:程序博客网 时间:2024/05/16 05:25

<?phpsession_start();@header("Content-Type:image/png");    //设置header格式为png格式

$str = "1,2,3,4,5,6,7,8,9,a,b,c,d,f,g"; $list = explode(",", $str);$cmax = count($list) - 1;$verifyCode = '';for ( $i=0; $i < 5; $i++ ){      $randnum = mt_rand(0, $cmax);      $verifyCode .= $list[$randnum];      }$_SESSION['code'] = $verifyCode;

 

$Code = $_SESSION['code'];      //页面传递过来的随机验证码$width = 191;          //验证码图片的宽度$height = 68;          //验证码图片的高度

$img=imagecreate($width,$height);$back=imagecolorallocate($img,0xFF,0xFF,0xFF); //背景色$pix=imagecolorallocate($img,187,230,247);  //模糊点颜色$fontColor=imagecolorallocate($img,41,163,238); //字体色$fontType='C:\Windows\Fonts\simhei.ttf';  //设置字体样式,这里是黑体mt_srand();          //绘模糊作用的点for($i=0;$i<1000;$i++){ imagesetpixel($img,mt_rand(0,$width),mt_rand(0,$height),$pix);}

imagettftext($img, 35, 0, 25, 52, $fontColor, $fontType, $Code);imagerectangle($img,0,0,$width-1,$height-1,$fontColor);imagepng($img);imagedestroy($img);?>

 
<img id="code"  src="master/inc/create_code.php"  width="80" height="22" onClick="this.src=this.src + '?Math.random()*10000';"  />
原创粉丝点击