茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    PHP+Ajax驗(yàn)證碼驗(yàn)證用戶登錄
    來(lái)源:易賢網(wǎng) 閱讀:2339 次 日期:2016-08-11 15:44:00
    溫馨提示:易賢網(wǎng)小編為您整理了“PHP+Ajax驗(yàn)證碼驗(yàn)證用戶登錄”,方便廣大網(wǎng)友查閱!

    用AJAX 驗(yàn)證用戶登錄的一個(gè)好處是不刷新跳轉(zhuǎn)頁(yè)面,外加用到驗(yàn)證碼就更安全了,摸索的寫了下。一共用到三個(gè)文件:

    yz.php:  生成驗(yàn)證碼的PHP 文件,將驗(yàn)證碼將在SESSION 里,供登錄時(shí)對(duì)比調(diào)用

    index.php: 用戶登錄的HTML 文件

    loginCheck.php: 驗(yàn)證用戶登錄的文件

    下面一一解析:

    yz.php 文件

    <?php

     session_start();

     //生成驗(yàn)證碼圖

     Header("Content-type: image/PNG");

     //長(zhǎng)與寬

     $im = imagecreate(44,18);

     // 設(shè)置背景色:

     $back = ImageColorAllocate($im, 245,245,245);

     // 填充背景色:

     imagefill($im,0,0,$back);

     srand((double)microtime()*1000000);

     $vcodes;

     //生成4位數(shù)字

     for($i=0;$i<4;$i++){

      $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255));

      $authnum=rand(1,9);

      $vcodes.=$authnum;

      imagestring($im, 5, 2+$i*10, 1, $authnum, $font);

     }

     //加入干擾象素

     for($i=0;$i<100;$i++){

      $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));

      imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);

     }

     ImagePNG($im);

     ImageDestroy($im);

     // 將四位的驗(yàn)證碼保存在 SESSION 里,登錄時(shí)調(diào)用對(duì)比

     $_SESSION["VCODE"]=$vcodes;

    ?>

    index.php: 注意,在這文件里不要取 $_SESSION["VCODE"], 否則會(huì)取晚一步的,刷新后才能顯示上一個(gè)驗(yàn)證碼

    在 loginCheck.php 里驗(yàn)證就好了

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml"> 

    <head>

    <meta http-equiv="Content-Type" content="text/html;charset=gb2312">

    <title>管理后臺(tái)| 請(qǐng)登錄</title>

    <link rel="stylesheet" type="text/css" href="\css\a.css">

    <style type="text/css">

    <!--

      #main{

       font-family:宋體;

       font-size:10pt;

       text-align:center;

       margin-top:510px;

      }

      body{

       background-attachment:fixed;

       background-position:center;

       background-image:url(./images/w2.jpg);

       background-repeat: no-repeat;

      }

      #authCode{background-Color:#F8F9FF;}

      table{text-align:center;}

    //-->

    </style>

    <script type="text/javascript" src="./js/trim.js"></script>

    <script type="text/javascript">

    <!--

     function clearX(){

      document.getElementById('authCode').value="";

     }

     // 點(diǎn)擊圖片重新獲得新的驗(yàn)證碼:

     function getVCode() { 

      var vcode=document.getElementById('vcode'); 

      vcode.src ='yz.php?nocache='+new Date().getTime(); 

     }

     //定義XMLHttpRequest對(duì)象

     var xmlHttp;     

     // 創(chuàng)建 XMLHttpRequest:

     function createXmlHttpRequest(){

     var xmlHttp=null;

     try{

      // Firefox, Opera 8.0+, Safari

      xmlHttp=new XMLHttpRequest();

     }catch(e){

      // Internet Explorer

      try{

      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

      }catch(e){

      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

      }

     }

     return xmlHttp;

     }

     // AJAX 檢查登錄: 有密碼,要用POST 提交

     function login(){

      var authCode=trim(document.getElementById('authCode').value);

      var username=trim(document.getElementById('username').value);

      var password=trim(document.getElementById('password').value);

      if(username=="" || password=="" || authCode==""){

       alert("請(qǐng)輸入用戶名和密碼和驗(yàn)證碼!");

       return false;

      }else{

       if(!xmlHttp) xmlHttp=createXmlHttpRequest();

        var send_string="username="+username+"&password="+password+"&authCode="+authCode+"&fresh="+Math.random();

        xmlHttp.open("POST","loginCheck.php",true); 

        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 

        xmlHttp.send(send_string); 

        xmlHttp.onreadystatechange=function(){

         if(xmlHttp.readystate==4 && xmlHttp.status==200){

          var answer=xmlHttp.responseText;

          if(answer=="ok")                     //跳轉(zhuǎn)到管理中心頁(yè)面

           window.location.href="adminCenter.php";

          else{

           alert("用戶名密碼或驗(yàn)證碼不正確! 請(qǐng)重新輸入!");

           document.getElementById('username').focus();

          }

        }

       }

      }

     }

    //-->

    </script>

    </head>

    <body onload="document.getElementById('username').focus();">

     <div id="main">

       <table>

         <tr>

         <td>用戶名:<input type="text" id="username" /></td>

         <td>密   碼:<input type="password" id="password" /></td>

         <td>驗(yàn)證碼:<input type="text" id="authCode" size="6" maxlength="4" value="驗(yàn)證碼" onfocus="clearX()"/></td>

         <td><img id="vcode" src="yz.php" alt="看不清?點(diǎn)擊換一張" onclick="getVCode()" /></td>

         <td><input id="loginButton" type="submit" value="登 錄" onclick="login()"/></td>

         </tr>

        </table>

     </div>

    </body>

    </html>

    loginCheck.php  驗(yàn)證用戶登錄的文件

    <?php 

     session_start();

     include("../conn/connDB.php");

     // 取得POST過來(lái)的參數(shù):

     $username=$_POST["username"];

     $password=md5($_POST["password"]);

     $authCode=$_POST["authCode"];       

     $feedback="no";

    //對(duì)比是否==SESSION中的驗(yàn)證碼,不能放在客戶端做,否則取不正確的值

     if($authCode==$_SESSION["VCODE"]){

       $SQL="select * from users where username='$username' and password='$password'";

       $result=mysql_query($SQL);

       $rows=mysql_num_rows($result);

      if($rows==1)                       // 驗(yàn)證成功

       $feedback="ok";

       $_SESSION["admin"]=true;           //為了后臺(tái)安全,存入SESSION,表明 ADMIN 已登錄,供后面調(diào)用

      }

     echo $feedback;

    ?>

    以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:PHP+Ajax驗(yàn)證碼驗(yàn)證用戶登錄
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報(bào)班

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)