In the controller:
/** * Output Verification Code */Public Function getverify () {$VModle =new \think\verify (); $VModle->codeset= ' 0123456789 '; $VModle->length=4; $VModle->entry (); }
The HTML in the page
<input type= "Text" name= "verify" placeholder= "Verification Code" class= "Form-control" style= "width:100px;float:left;" >
Javacsript Instant Refresh
$ ("#verifyimg"). Click (function () {var verifyurl = "{: U (' public/getverify ', '", ')} "; var time = new Date (). GetTime (); $ (this). attr ({"src": verifyurl+ "/" +time}); });
Asynchronous validation is correct:
/** * asynchronously verifies that the verification code is correct * @params verify; */ public function Ajaxcheckverify () { if (!is_post) { $data [' Status '] = 0; } else{ $VModle =new \think\verify (); $code = trim (I (' verify ')); if (! $VModle->check ($code)) { $data [' Status '] = 0; $data [' Data '] = $code; } else{//Validation Successful $ data[' status '] = 1; } } echo json_ Encode ($data); }
This article is from "Buffy Rain Blog" blog, please be sure to keep this source http://bafeiyu.blog.51cto.com/5401101/1607492
Thinkphp Verification Code Setup and refresh