代码如下 | 复制代码 |
<?php教程 /* * Created on 2011-3-11 * Programmer : xiaoyao, QQ:1045195056 验证通过判断输入值与$_SESSION['check_pic']值 */ session_start(); function RandAscii($number){//$number产生数字和字母个数 $arr=array('0','1','2','3','4','5','6','7','8','9', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','w','v','u','x','y','z'); for ($i=1;$i<=$number;$i++) { $rand= $rand.$arr[rand(0,35)]; } return $rand; } $rand=RandAscii(4); $_SESSION['check_pic']=$rand;//随机产生的四个数赋值session中,用于验证。 for($i=0;$i<10;$i++){ //画干扰线,10条 } header("Content-type: image/jpeg");//输出图片 |
调用方法
代码如下 | 复制代码 |
<?php /* * Created on 2011-3-11 * Programmer : xiaoyao, QQ:1045195056 验证通过判断输入值与$_SESSION['check_pic']值 */ session_start();//开启session if(isset($_POST['check'])) { if($_POST['check']) { if($_POST['check']==$_SESSION['check_pic']) { echo " 验证码正确".$_SESSION['check_pic']; } else { echo " 验证码错误".$_SESSION['check_pic']; } } } ?> <FORM METHOD=POST ACTION=""> <img src="index.php"><br> <!----链接图片---> <input type="text" name="check" > <input type="submit" value="提交"> </FORM> |