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" + );})