问答项目---登陆也要做验证!(JS和PHP验证)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                问答项目---登陆也要做验证!(JS和PHP验证)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                簡單JS示例:
var login = $( 'form[name=login]' );login.submit( function () {if (validate.loginAccount && validate.loginPwd) {return true;}$( 'input[name=account]', login ).trigger('blur');$( 'input[name=pwd]', login ).trigger('blur');return false;} );$( 'input[name=account]', login ).blur( function () {var account = $( this ).val();var span = $( '#login-msg' );if (account == '') {span.html( '請(qǐng)?zhí)钊霂ぬ?hào)' );validate.loginAccount = false;return;}} );$( 'input[name=pwd]', login ).blur( function () {var account = $( 'input[name=account]', login ).val();var pwd = $( this ).val();var span = $( '#login-msg' );if (pwd == '') {span.html( '請(qǐng)?zhí)顚懨艽a' );validate.loginPwd = false;return;}if (account == '') {span.html( '請(qǐng)?zhí)钊霂ぬ?hào)' );validate.loginAccount = false;return;}var data = {account : account,password : pwd};$.post(CONTROL + 'checkLogin', data, function (status) {if (status) {span.html( '' );validate.loginAccount = true;validate.loginPwd = true;} else {span.html( '帳號(hào)或密碼不正確' );validate.loginAccount = false;validate.loginPwd = false;}}, 'json');} );異步驗(yàn)證:
//異步驗(yàn)證登錄帳號(hào)與密碼 Public function checkLogin () {if (!$this->isAjax()) halt('頁面不存在');$account = $this->_post('account');$where = array('account' => $account);$pwd = M('user')->where($where)->getField('password');if (!$pwd || $pwd != $this->_post('password', 'md5')) {echo 0;} else {echo 1;} }登錄表單處理:
//登錄表單處理 Public function login () {if (!$this->isPost()) halt('頁面不存在');$db = M('user');$where = array('account' => $this->_post('account'));$field = array('id', 'username', 'password', 'logintime', 'lock');$user = $db->where($where)->field($field)->find();if (!$user || $user['password'] != $this->_post('pwd', 'md5')) {$this->error('帳號(hào)或密碼錯(cuò)誤');}if ($user['lock']) {$this->error('帳號(hào)被鎖定');}if (isset($_POST['auto'])) {$value = $user['id'] . '|' . get_client_ip() . '|' . $user['username'];$value = encrytion($value, 1);@setcookie('auto', $value, C('AUTO_LOGIN_LIFETIME'), '/');}//每天登錄增加經(jīng)驗(yàn)$today = strtotime(date('Y-m-d'));$where = array('id' => $user['id']);if ($user['logintime'] < $today) {$db->where($where)->setInc('exp', C('LV_LOGIN'));}$db->where($where)->save(array('logintime' => time()));session('uid', $user['id']);session('username', $user['username']);redirect($_SERVER['HTTP_REFERER']); }?
轉(zhuǎn)載于:https://www.cnblogs.com/e0yu/p/7446055.html
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的问答项目---登陆也要做验证!(JS和PHP验证)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 原型设计真的对用户体验那么重要吗?
- 下一篇: GIt本地相关操作(一)
