PHP ??? ?? ?? ??
?? ?????? ??? ? ????? ????. ????? ???? ??? ???? ??? ???????.
?? ??? ???? ???? ?? ??? ????.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no" /> <title>登錄頁面實例展示</title> <link rel="stylesheet" type="text/css" href="/phpMyAdmin/login.css"/> </head> <body> <p> <span> <input type="text" name="code" id="code" class="pf_ipt_verify w230" placeholder="驗證碼" autocomplete="off" tabindex="3"/> <img src="/phpMyAdmin/code.php" onClick="this.src='/phpMyAdmin/code.php?nocache='+Math.random()" style="cursor:hand"> </span> </p> </body> </html>
???? ???? ?? ?? ?????. ???? ???? ?????? ?? ???? ?? ???? ?? ??? ??? ?????.
?? ????? ???? ??? ??? ????.
<?php session_start(); Header("Content-type:image/PNG"); $im = imagecreate(150,45); $back = imagecolorallocate($im, 245, 245, 245); imagefill($im, 0,0, $back); $vcodes = ""; for($i = 0; $i < 4; $i++){ $font = imagecolorallocate($im, rand(100, 255), rand(0, 100), rand(100, 255)); $authnum = rand(0, 9); $vcodes .= $authnum; imagestring($im, 5, 50 + $i * 10, 20, $authnum, $font); } $_SESSION['VCODE'] = $vcodes; for($i=0;$i<200;$i++) { $randcolor = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); imagesetpixel($im, rand()%150, rand()%150, $randcolor); // } imagepng($im); imagedestroy($im); ?>
?? ??? ?? ????? ???????.
??? ??? ??? ?? ??? ?????. ??? ??? ??? ???? ???, ?? ??? ??? ???? ???? ????.
if(!$_POST['code']){ echo('驗證碼不能為空'); return; }else if($_POST['code']!=$_SESSION['VCODE']){ echo('驗證碼不正確'); return; }