PHP 개발 인증코드에 대한 인증코드 사용

인증 코드 사용

새 양식 만들기

<?php
 
 if(isset($_REQUEST['code']))
 {
     session_start();
     if (strtolower($_REQUEST['code'])==$_SESSION['code'])
     {
         header('Content-type: text/html; charset=UTF8');
         echo '<font color="#0000CC">输入正确</font>';
     }
     else{
         header('Content-type: text/html; charset=UTF8');
         echo '<font color="#CC0000"><b>输入错误</b></font>';
     }
     exit();
 }
 
 ?>
 <!DOCTYPE html>
 <html>
 <head>
     <meta charset="utf-8"/>
     <title>确认验证</title>
 </head>
 <body>
 <form method="post" action="form.php">
     <p>验证码图片:<img id="captcha_img" border="1" src="captcha-2.php?r=<?php echo rand();?>" width="100" height="30">
 
     </p>
     <p>请输入图片的内容:<input type="text" name="code" value=""/></p>
     <p><input type="submit" value="提交" style="padding:6px 20px;"></p>
 </form>
 </body>
 </html>

코드 설명:

<?php
 
 if(isset($_REQUEST['code']))
 {
     session_start();
     if (strtolower($_REQUEST['code'])==$_SESSION['code'])
     {
         header('Content-type: text/html; charset=UTF8');
         echo '<font color="#0000CC">输入正确</font>';
     }
     else{
         header('Content-type: text/html; charset=UTF8');
         echo '<font color="#CC0000"><b>输入错误</b></font>';
     }
     exit();
 }
 
 ?>
 <!DOCTYPE html>
 <html>
 <head>
     <meta charset="utf-8"/>
     <title>确认验证</title>
 </head>
 <body>
 <form method="post" action="form.php">
     <p>验证码图片:
         <img src="captcha-2.php" alt="验证码,看不清楚,换一张"
          onclick="this.src = this.src + '?' + new Date().getTime();" />
     </p>
     <p>请输入图片的内容:<input type="text" name="code" value=""/></p>
     <p><input type="submit" value="提交" style="padding:6px 20px;"></p>
 </form>
 </body>
 </html>

html 인증 코드 확인 페이지를 만들고 제출된 값을 post submit을 통해 form.php 파일에 전달합니다. 사진은 captcha-2.php로 가져오며,

onclick="this.src = this.src + '?' + new Date().getTime();

사진을 클릭할 때마다 새로운 사진이 무작위로 생성됩니다.

<?php
 
 if(isset($_REQUEST['code']))
 {
     session_start();
     if (strtolower($_REQUEST['code'])==$_SESSION['code'])
     {
         header('Content-type: text/html; charset=UTF8');
         echo '<font color="#0000CC">输入正确</font>';
     }
     else{
         header('Content-type: text/html; charset=UTF8');
         echo '<font color="#CC0000"><b>输入错误</b></font>';
     }
     exit();
 }

php 판단, SESSION을 통해 저장된 검증 정보를 호출하여 사용자의 원래 입력을 판단하여 서버에 저장된 정보와 비교하여 같으면 입력이 맞는 것, 같지 않으면 입력이 입니다

현재 영숫자 인증코드 제작이 완료되었습니다.

지속적인 학습
||
<?php session_start(); $image = imagecreatetruecolor(100,30); $bgcolor = imagecolorallocate($image,255,255,255);//#FFFFFFFFFFFF imagefill($image,0,0,$bgcolor); $captch_code=""; for ($i=0;$i<4;$i++){ $fontsize = 6; $fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120)); $data='abcdefghijklmnopqrstuvwxyz1234567890'; $fontcontent=substr($data,rand(0,strlen($data)),1); $captch_code.="$fontcontent"; $x = ($i * 100/4)+rand(5,10); $y = rand(5,10); imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor); } $_SESSION['code']=$captch_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,29),$pointcolor); } for($i=0;$i<5;$i++){ $linecolor = imagecolorallocate($image,rand(60,220),rand(60,220),rand(60,220)); imageline($image,rand(1,99),rand(1,29),rand(1,99),rand(1,29),$linecolor); } header('content-type: image/png'); imagepng($image); //销毁 imagedestroy($image); ?>
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!