首頁 > 後端開發 > PHP問題 > php如何寫入註冊登入驗證碼

php如何寫入註冊登入驗證碼

發布: 2023-02-27 21:52:01
原創
3290 人瀏覽過

php如何寫入註冊登入驗證碼

 authimg.php產生驗證碼的檔案:

<?

 $IsLetter = false; //是否出现字母
 session_start();
 $Num  = $_GET["n"];
 
 //生成验证码图片
 header("Content-type: image/PNG");
 $im   = imagecreate(46,20);
 srand((double)microtime()*1000000);
 $Red  = rand(0,200);
 $Green  = rand(0,200);
 $Blue  = rand(0,200);
 $Color  = imagecolorallocate($im, $Red, $Green, $Blue);
 $BackGround = imagecolorallocate($im, 255,255,255);
 imagefill($im,0,0,$BackGround);
 
 if($IsLetter)
 {
  $a = substr(md5($Num*10000000000000000),0,1);
  $b = substr(md5($Num*10000000000000000),4,1);
  $c = substr(md5($Num*10000000000000000),8,1);
  $d = substr(md5($Num*10000000000000000),12,1);
 }
 else
 {
  $a = substr(hexdec(md5($Num*10000000000000000)),2,1);
  $b = substr(hexdec(md5($Num*10000000000000000)),3,1);
  $c = substr(hexdec(md5($Num*10000000000000000)),4,1);
  $d = substr(hexdec(md5($Num*10000000000000000)),5,1);
 }
 
 $Authnum    = strtoupper($a.$b.$c.$d);
 
 $_SESSION["Authnum"] = $Authnum;
 
 imagestring($im, 5, 5, 2, $Authnum, $Color);
 for($i=0;$i<200;$i++)   //加入干扰象素
 {
     $randcolor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
     imagesetpixel($im, rand()p , rand()0 , $randcolor);
 }
 imagepng($im);
 imagedestroy($im);
?>
登入後複製

需要顯示驗證碼的檔案:

<?
session_start();
$AuthInput = $_POST["AuthInput"];
$action = $_GET["action"];
?>
<script language="javascript">
function lyalert(){
if( addform.AuthInput.value=="") {
alert("请填写验证码");
document.addform.AuthInput.focus();
return false;
} 
}
</script>
<form name="addform" method="post" action="?action=save" id="addform" onsubmit="return lyalert()">
<table width="500" border="1" cellpadding="5" cellspacing="0">
<tr><td>验证码:</td>
<td><input name="AuthInput" type="text" id="AuthInput"  size="8" maxlength="4" /><script>document.write("<img src=\"authimg.php?n=",Math.random(),"\" />");</script></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="Button1" value="确定" id="Button1" /></td>
</tr>
</table>
<p> </p>
</form>
  
<?
if($action==&#39;save&#39;)
{
if ($_SESSION["Authnum"] != $AuthInput)
{
?>
<script language="javascript">
alert("验证码输入不正确");
</script>
<? 
}
else
{
 ?>  
<script language="javascript">
 alert("提交成功!");
</script>
<?
 
 
 
} 
}
?>
登入後複製

建議:php伺服器

以上是php如何寫入註冊登入驗證碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板