不知道為什么,我的驗證碼,當什么都不輸入時,點登錄彈出輸入正確,輸入正確時彈出輸入錯誤,可以麻煩再幫我看看嗎?<?php//1、創(chuàng)建一個真空彩色圖像 $image = imagecreatetruecolor(100,30);? ? //2、為圖像分配顏色 $bgcolor = imagecolorallocate($image,255,255,255);? ? //3、填充圖像 imagefill($image,0,0,$bgcolor);? ?//4、在圖像中添加隨機數(shù)字 // 數(shù)字+字母驗證碼for ($i=0; $i < 4; $i++) { $fontsize = 8; // 0-120 為深色區(qū),能更好的在淺色背景中識別驗證碼 $fontcolor = imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120)); // 制作字典 ?并去除容易混淆的字符(l 與 1, z 與 2,等等) $data = 'abcdefghijkmnqprstuvwxy3456789'; // 通過截取字符串內容方法,獲得隨機字符 $fontcontent = substr($data, rand(0,strlen($data)),1); $captcha_code = $fontcontent; // 生成的驗證內容不重疊 $x = ($i*100/4) + rand(5,10); // 生成的驗證內容不齊平 $y = rand(5,10); // 用 $fontcolor 顏色將字符串 $fontcontent 畫到 $image 所代表的圖像的 $x,$y 坐標處 imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);}? ?//增加干擾元素$_SESSION['authcode'] = $captcha_code;? ? for($i=0;$i<200;$i++){? ? $pointcolor = imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));? ? imagesetpixel($image,rand(1,99),rand(1,99),rand(1,99));? ? }? ? //增加線干擾? ? for($i=0;$i<3;$i++){? ? ? ? $linecolor = imagecolorallocate($image,rand(80,200),rand(80,200),rand(80,200));? ? ? ? imageline($image,rand(1,99),rand(1,29),rand(1,99),rand(1,29),$linecolor);? ? } header('content-type:image/png'); imagepng($image); imagedestroy($image);zzmm.php<?phpheader('content-type:text/html;charset=utf-8');if(isset($_REQUEST['authcode'])){ session_start(); if(strtolower($_REQUEST['authcode']) == $_SESSION['authcode']){ echo '輸入正確'; }else{ echo '輸入錯誤'; } exit();}?><!DOCTYPE html><html>? ?<head>? ? ? <meta charset="utf-8"/>? ? ? <title>驗證碼確認</title>? ?</head>? ?<body>? ?<form method="post" action="zzmm.php">? ?<p>驗證碼圖片:<img border = "1" src="zzm.php?r=<?php echo rand();?>"width:100px,height:100px" /></p>? ?<p>請輸入驗證碼內容:<input type="text" name="authcode" value="" /></p>? ?<p> <input type="submit" value="提交" style="padding: 6px 20px;" /></p>? ?</form>? ?</body></html>
添加回答
舉報
0/150
提交
取消