Implementation of thinkphp Verification code (form, AJAX implementation validation) _php instance

Source: Internet
Author: User
Tags button type php code php write

Two Verification code verification implementation , a direct in the form form Submission button implementation verification, a use of Ajax pass parameters to achieve validation:

1, directly on the form form Submit button implementation verification, in the controller VerifyController.class.php write the following code:

namespace Home\controller;
Use Think\controller;
Class Verifycontroller extends Controller {public
function index () {
$this->display ();
}
Public Function Checklogin () {
$verify =new \think\verify ();
$code =i (' post.verify ');//form Authentication Code
if ($verify->check ($code)) {
$this->success (' Authenticode correct ');
} else{
$this->error (' Authentication code error ');
}
Public Function Verify ()
{
//Instantiate Verify object
$verify = new \think\verify ();
Configure the authentication code parameter
$verify->fontsize = 14;//Verify Code font size
$verify->length = 4;//Verify code digits
$verify->imageh = 34; Verify code height
$verify->USEIMGBG = true;//Open Authenticode background
$verify->usenoise = false;//Turn off verification code interference clutter
$verify-> Entry ();
}

The code in the View verify/index.html is as follows:

<! DOCTYPE html>
 
 

2, the use of Ajax transfer parameters to achieve validation, in the controller VerifyController.class.php code is as follows:

namespace Home\controller;
Use Think\controller;
Class Verifycontroller extends Controller {public
function index () {
$this->display ();
}
Public Function Checklogin () {
$verify =new \think\verify ();
$code =$_post[' code '];//ajax verification code to get
if ($verify->check ($code)) {
$this->ajaxreturn (1);
} else{
$this->ajaxreturn (0);
}
}
Public Function Verify ()
{
//Instantiate Verify object
$verify = new \think\verify ();
Configure the authentication code parameter
$verify->fontsize = 14;//Verify Code font size
$verify->length = 4;//Verify code digits
$verify->imageh = 34; Verify code height
$verify->USEIMGBG = true;//Open Authenticode background
$verify->usenoise = false;//Turn off verification code interference clutter
$verify-> Entry ();
}

The code in the View verify/index.html is as follows:

<! DOCTYPE html>  

In the 2nd method, do not forget to download jquery.min.js file download Address: http://www.jq22.com/jquery-info122

To configure the address in the configuration file common/conf/config.php:

return Array (/ 
* Address replacement *
/' tmpl_parse_string ' =>array ( 
' __js__ ' =>__root__. ') /public/js ',
),
);

The above is a small series to introduce the implementation of the Thinkphp Verification Code (form, Ajax use verification), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

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.