Using the Verification Code feature in thinkphp3.2

Source: Internet
Author: User

For the security of the site, the use of verification code technology is more common, today according to the thinkphp3.2 full development manual example (address http://document.thinkphp.cn/manual_3_2.html#verify), always error , the verification code cannot be displayed because the GD library was not opened in the php.ini file.

Just remove the Extension=php_gd2.dll comment from the configuration file php.ini (Php_gd2.dll GD library image function Library GD2).

Generate Verification Code

      Public function code () {    $Verifynew  Verify ();     $Verify->fontsize =;     $Verify->length   = 4;     $Verify false ;     $Verify-entry ();}

Login Check

functionDo_login () {//get the user name and password, and so on. And in the database, there is a user allowed to log on otherwise output error page            $username=$_post[' username ']; $password=$_post[' Password ']; $code=$_post[' Code ']; $verify=New\think\verify (); $r=$verify->check ($code, ‘‘); if(!$r){                $this->error (' Verification code 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 (' The user does not exist '); }        }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.