欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP登錄(ajax提交數(shù)據(jù)和后臺(tái)校驗(yàn))實(shí)例分享

 更新時(shí)間:2016年12月29日 09:20:32   作者:yangzailu1990  
本文主要分享了PHP登錄(ajax提交數(shù)據(jù)和后臺(tái)校驗(yàn))的實(shí)例代碼,具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧

1.前臺(tái)ajax數(shù)據(jù)提交

<form id="login_form" action="" method="POST">
  <div class="login_frame" style="position:relative";>
    <div class="login_gl" style="margin-top:35px;">
      <span class="login_wz" >后臺(tái)管理系統(tǒng)</span>
    </div>
    <div class="login_user">
      <input id="username" name="username" type="text" placeholder="請(qǐng)輸入您的用戶名" value="" style="width:100%;height:32px;border-style:none;font-size:16px;color:#959595;"/>
    </div>
    <div class="login_user">
      <input id="password" name="password" type="password" placeholder="請(qǐng)輸入您的密碼" value="" style="width:100%;height:32px;border-style:none;font-size:16px;color:#959595;"/>
    </div>
    <div id="login_btn" class="login_log">
      <span style="font-size:16px;">登錄</span>
    </div>
  </div>
  </form>
</div>
<script type="text/javascript">
  $("#login_btn").click(function(){
    var username = $.trim($("#username").val());
    var password = $.trim($("#password").val());
    if(username == ""){
      alert("請(qǐng)輸入用戶名");
      return false;
    }else if(password == ""){
      alert("請(qǐng)輸入密碼");
      return false;
    }
    //ajax去服務(wù)器端校驗(yàn)
    var data= {username:username,password:password};
    $.ajax({
      type:"POST",
      url:"__CONTROLLER__/check_login",
      data:data,
      dataType:'json',
      success:function(msg){
        //alert(msg);
        if(msg==1){
           window.location.href = "{:U('Index/personal')}";  
        }else{
          alert("登錄失敗,請(qǐng)重試!");
        }
      }
    });
});  
</script>

2.后臺(tái)校驗(yàn):

* */
  public function check_login(){
    $password=I('param.password');
    $username=I('param.username');
    $data["name"]=$username;
    $user=M('systemuser');
    $list=$user->where($data)->find();
    $return=0;
    if($list!=""){
      if($list['password']==md5($password) && $list['status'] == 1){
        //登錄時(shí)間和登錄IP
        $public = new PublicController();
        $lastlogonip=$public->ip_address();
              
        $time=$time=date("Y-m-d H:i:s", time());
        $where=array('id'=>$list['id']);
        
        $user->where($where)->save(array('lastlogonip'=>$lastlogonip,'lastlogontime'=>$time));
        $this->login($list);
        $return=1;//登錄成功
      }
    }else{
      $return=2;//登錄失敗
    }
    $this->ajaxReturn($return);
  }

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論