<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                網頁上經常有一些自動登錄的checkbox,勾選后,下次進入該網站,無需登錄,即可執行一些需要登錄才能執行的操作。上班無事,用thinkphp做了下。 參考網址:[thinkphp實現自動登錄](https://www.cnblogs.com/kongxs/archive/2013/11/14/3423181.html) [TOC] ## 思路分析 ### 初次登錄時: 首先,加密 其次,寫入cookie ### 再次登錄時: 首先,解密 其次,判斷信息是否一致 ## 一、HTML ``` <form action="{:U('login')}" method='post' name='login'> <p> <input type="checkbox" name='auto' checked='1' class='auto' id='auto'/> <label for="auto">下次自動登錄</label> </p> </form> ``` ## 二、自定義加密函數 文件位置:Index/Common/common.php ``` /** * 異位或加密字符串 * @param [String] $value [需要加密的字符串] * @param [integer] $type [加密解密(0:加密,1:解密)] * @return [String] [加密或解密后的字符串] */ function encryption ($value, $type=0) { $key = md5(C('ENCTYPTION_KEY')); if (!$type) { return str_replace('=', '', base64_encode($value ^ $key)); } $value = base64_decode($value); return $value ^ $key; } ``` ## 三、配置文件 ``` <?php return array( //用于異位或加密的KEY 'ENCTYPTION_KEY' => 'www.psnav.com', //自動登錄保存時間 'AUTO_LOGIN_TIME' => time() + 3600 * 24 * 7, //一個星期 ); ?> ``` ## 四、后臺處理 ``` /** * 登錄表單處理 */ Public function login () { if (!$this->isPost()) { halt('頁面不存在'); } //提取表單內容 $account = $this->_post('account'); $pwd = $this->_post('pwd', 'md5'); $where = array('account' => $account); $user = M('user')->where($where)->find(); if (!$user || $user['password'] != $pwd) { $this->error('用戶名或者密碼不正確'); } if ($user['lock']) { $this->error('用戶被鎖定'); } //處理下一次自動登錄 if (isset($_POST['auto'])) { $account = $user['account']; $ip = get_client_ip(); $value = $account . '|' . $ip; $value = encryption($value); @setcookie('auto', $value, C('AUTO_LOGIN_TIME'), '/'); } //登錄成功寫入SESSION并且跳轉到首頁 session('uid', $user['id']); header('Content-Type:text/html;Charset=UTF-8'); redirect(__APP__, 3, '登錄成功,正在為您跳轉...'); } ``` ## 五、自動登錄處理 ``` /** * 自動運行的方法 */ Public function _initialize () { //處理自動登錄 if (isset($_COOKIE['auto']) && !isset($_SESSION['uid'])) { $value = explode('|', encryption($_COOKIE['auto'], 1)); $ip = get_client_ip(); //本次登錄IP與上一次登錄IP一致時 if ($ip == $value[1]) { $account = $value[0]; $where = array('account' => $account); $user = M('user')->where($where)->field(array('id', 'lock'))->find(); //檢索出用戶信息并且該用戶沒有被鎖定時,保存登錄狀態 if ($user && !$user['lock']) { session('uid', $user['id']); } } } //判斷用戶是否已登錄 if (!isset($_SESSION['uid'])) { redirect(U('Login/index')); } } ``` if(isset($_COOKIE['auto']) && !$_SESSION['uid']){}這個判斷用來判斷用戶的cookie中有auto值,并且沒有登錄時,假如驗證成功,則進一步驗證ip與上次ip是否一致,驗證用戶名是否存在于數據庫中,如果驗證通過,則寫入session,由此實現自動登錄。其中encryption($_COOKIE['auto'],1) 是一個解密函數,將加密后的用戶名和密碼解密出來進行驗證。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看