Use of verification code for PHP development verification code
Use of verification code
New form
<?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>確認(rèn)驗證</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>請輸入圖片的內(nèi)容:<input type="text" name="code" value=""/></p> <p><input type="submit" value="提交" style="padding:6px 20px;"></p> </form> </body> </html>
Code explanation:
<?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>確認(rèn)驗證</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>請輸入圖片的內(nèi)容:<input type="text" name="code" value=""/></p> <p><input type="submit" value="提交" style="padding:6px 20px;"></p> </form> </body> </html>
Make an html verification code verification page, pass the submitted value to the form.php file through post submission, and import the picture into captcha-2.php,
onclick="this.src = this.src + '?' + new Date().getTime();
Every time you click Picture randomly generates a new picture.
<?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 judgment, calling the verification information stored through SESSION, judging the user's original input and comparing it with the information stored on the server. If they are equal, the input is correct, if they are not equal, the input is incorrect.
Now the production of alphanumeric verification code is completed.