Thinkphp 3.2 Add verification code how to Add.

Source: Internet
Author: User

1, in the Home module indexController.class.php, add the following code

<?phpnamespace Home\controller; UseThink\controller;classBookcontrollerextendsController { Public functionVerify_c () {$Verify=New\think\verify (); $Verify->fontsize = 18; $Verify->length = 4; $Verify->usenoise =false; $Verify->codeset = ' 0123456789 '; $Verify->imagew = 130; $Verify->imageh = 50; //$Verify->expire = +;        $Verify-entry (); }          Public functionimg () {$this-display (); }}

2. In the IMG view, add the following code

<Scripttype= "Text/javascript"src= "__public__/js/jquery2.0.3.min.js"></Script><Pclass= "Top15 captcha"ID= "Captcha-container">    <inputname= "Verify"width= "50%"Height= " the"class= "Captcha-text"placeholder= "Verification Code"type= "text">    <imgwidth= "+"class= "left15"Height= " the"alt= "Verification Code"src= "{: U (' Home/book/verify_c ', Array ())}"title= "Click to refresh"></P>        <Scripttype= "Text/javascript">            $(function(){                varcaptcha_img= $('#captcha-container'). Find ('img'); varverifyimg=captcha_img.attr ("src"); Captcha_img.attr ('title', 'Click Refresh'); Captcha_img.click (function(){                    if(Verifyimg.indexof ('?')>0){                        $( This). attr ("src", Verifyimg+'&random='+math.random ()); }Else{                        $( This). attr ("src", Verifyimg.replace (/\?. *$/,"')+'?'+math.random ());            }                }); })        </Script>

This will allow you to display the verification code.

Reference Study website: http://blog.csdn.net/yafei450225664/article/details/40424025

Thinkphp 3.2 Add verification code how to Add.

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.