Thinkphp Verification Code using a concise tutorial _php tutorial

Source: Internet
Author: User
first, the controller must be added to the verification code method admin/lib/action/loginaction.class.php
Knowledge Points:
1. Ob_clean function Use
2. Import method call think default class library
3. Image class Buildimageverify method use

The code is as follows:
Copy the Code code as follows:
Public Function Verify () {
Ob_clean ();
Ob_clean function empties the previous output
Import (' ORG. Util.image ');
Import calls the Image.class.php class file in the expansion pack extend/library/org/util/in the message/thinkphp framework directory
Image::buildimageverify ();
Call the Buildimageverify method to generate the verification code, the default parameter is ($length =4, $mode =1, $type = ' png ', $width =48, $height =22, $verifyName = ' Verify '), interested friends can study the following image class
}

Second, add the Verification code module in the template file admin/tpl/login/index.html
Knowledge Points:
1. Verification Code Image Call
2, JS related operating procedures to understand
3. __public__ Constants

Add the following code after the Password entry box:
Copy the Code code as follows:





__public__ constants can be found in the page after loading, "View page source files" in the definition of the __public__ directory, the default is the project root message under the public directory, the following explains how to customize __public__ system constants
jquery file, the only way to invoke jquery is to load this file.

Here the specific code will be posted below, in fact, just define a change_code function, that is, replace the verification Code asynchronous operation (can be changed without refreshing the page)

Message Board BackGround




Login.js files in the message/public/directory
The contents of the file are as follows:
Copy the Code code as follows:
Verifyurl = ' http://localhost/message/admin.php/Login/verify ';
Defining the CAPTCHA Path
function Change_code (obj) {
$ ("#code"). attr ("src", verifyurl+ '/' +math.random ());
Dynamic generation of CAPTCHA methods, interested friends can delve into the next JQ method
return false;
}

Another: __public__ file is defined in message/admin/conf/config.php
In the configuration, you can change the __public__ path by adding the following:
The configuration is as follows:
Copy the Code code as follows:
Constant-dependent configuration
' Tmpl_parse_string ' = Array (
' __public__ ' = __root__. '/' . App_name. '/public ',
The path changes to Message/admin/public, refresh the page, the verification code can still be refreshed, then the JS is in effect, you can also "view the page source file"
),

http://www.bkjia.com/PHPjc/736799.html www.bkjia.com true http://www.bkjia.com/PHPjc/736799.html techarticle first, the controller must be added to the verification code method admin/lib/action/loginaction.class.php knowledge Points: 1, Ob_clean function use 2, import method call think default class Library 3, Image class ...

  • 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.