标题文档
<!DOCTYPE <html <head> <meta <title>无标题文档</title> <script function refresh_code() { form1.imgcode.src="verifycode.php?a="+Math.random(); } </script> </head> <body> <form <label <input <img <a <input </form> </body> </html> |
verifycode.php文件代码如下
<?php /* 图片验证码 Powered By KASON test <a href=" session_start(); $num=4;//验证码个数 $width=80;//验证码宽度 $height=20;//验证码高度 $code=‘ ‘; for($i=0;$i<$num;$i++)//生成验证码 { switch(rand(0,2)) { case case case } } $_SESSION["VerifyCode"]=$code; $image=imagecreate($width,$height); imagecolorallocate($image,255,255,255); for($i=0;$i<80;$i++)//生成干扰像素 { $dis_color=imagecolorallocate($image,rand(0,2555),rand(0,255),rand(0,255)); imagesetpixel($image,rand(1,$width),rand(1,$height),$dis_color); } for($i=0;$i<$num;$i++)//打印字符到图像 { $char_color=imagecolorallocate($image,rand(0,2555),rand(0,255),rand(0,255)); imagechar($image,60,($width/$num)*$i,rand(0,5),$code[$i],$char_color); } header("Content-type:image/png"); imagepng($image);//输出图像到浏览器 imagedestroy($image);//释放资源 ?> |
checkcode.php文件如下
<meta http-equiv="Content-Type" <?php ini_set(‘display_errors‘,‘Off‘); session_start(); if((strtoupper($_POST["code"])) ==strtoupper(($_SESSION["VerifyCode"]))){ print("验证码正确,"); }else{ print("验证码错误,"); } echo ?> |