Thinkphp verification code usage summary, thinkphp Summary

Source: Internet
Author: User

Thinkphp verification code usage summary, thinkphp Summary

The verification code in thinkphp can be called directly, which is very convenient. Let's take a look at a file named verify. class. php In the Think folder.

First, we need to have a template. I wrote a file named xx.html in the view folder, but nothing was written in it. In this case, we need to display the verification code in this file.

 function xx(){  $this->show();}function yzm(){  $yzm=new \Think\verify();  $yzm->entry();}

If you want to verify the code display, you can call the yzmruntime, which is expressed

<div>  </div>

In this way, the verification code can be called up. After the verification code is transferred, the verification button will be used in the input form in xx.html.

<div>  <input type="text" id="va"/>  <input type="button" id="btn"/></div>

The js Part I wrote below uses jquery, so we must introduce the jquery package before.

<Script type = "text/javascript"> $ ("# btn "). click (function () {var va =$ ("# va "). val (); $. ajax ({url: "_ CONTROLLER _/yz", data: {va: va}, type: "POST", dataType: "TEXT", success: function (data) {if (data) {alert ("Verification Successful") ;}else {alert ("Verification Failed") ;}}) ;}) </script>

Now let's write the yz method.

function yz(){  $yzm=new \Think\verify();  $va=$_POST["va"];   $aa=$yzm->check($va);  $this->ajaxReturn($aa,"eval");}

After this is done, we will find that the image will not be changed automatically when we click the image, so we will add a click event to the image, and each click will let the path go again

$ ("# Img1 "). click (function () {// If you only run $ (this) on other browsers except IE ). attr ("src", "_ CONTROLLER _/yzm"); // to increase its compatibility, we need to obtain a random number $ a = Math. random () * 10; $ (this ). attr ("src", "_ CONTROLLER _/yzm/aa" + );})

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