使用thinkphp3.2中的驗證碼功能

來源:互聯網
上載者:User

標籤:c   style   class   blog   code   java   

 

為了網站的安全性,使用驗證碼技術是比較常見的,今天按照thinkphp3.2完全開發手冊的例子試了一下(地址http://document.thinkphp.cn/manual_3_2.html#verify),總是報錯,沒法顯示驗證碼,原因原來是在PHP.INI檔案中沒有開啟GD庫。

 

只要將設定檔PHP.INI中的extension=php_gd2.dll注釋去掉就可以了(php_gd2.dll   GD 庫映像函數庫 GD2)。

產生驗證碼

     public function code(){    $Verify = new Verify();    $Verify->fontSize = 20;    $Verify->length   = 4;    $Verify->useNoise = false;    $Verify->entry();}

登入校正

function do_login(){            //擷取使用者名稱和密碼等。和資料庫中比對,有該使用者允許登入否則輸出錯誤頁面            $username=$_POST[‘username‘];            $password=$_POST[‘password‘];            $code=$_POST[‘code‘];            $verify = new \Think\Verify();            $r=$verify->check($code, ‘‘);            if(!$r){                $this->error(‘驗證碼錯誤!‘);            }            $m=M(‘User‘);            $where[‘username‘]=$username;            $where[‘password‘]=$password;            $i=$m->where($where)->count();            if($i>0){                $this->redirect(‘User/index‘);            }else{                $this->error(‘該使用者不存在‘);            }        }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.