TP in the verification code is a lot simpler, less to the original more cumbersome operation, below to take a look at the verification code example!
yzm1.html Front Desk templates
<formAction=""Method= "POST"> <inputtype= "text"name= "Code"ID=""> <imgsrc= "{: U (' Yzm ')}"alt=""> <inputtype= "Submit"value= "Submit"> </form>
Controller page
<?phpnamespace Home\controller; UseThink\controller;classUsercontrollerextendsController { Public functionindex () {Echo"Index"; } Public functionYzm () {//$Verify = new \think\verify (); Set font size//$Verify->fontsize = 30; Use background image//$Verify->useimgbg=true; Whether there is interference line//$Verify->usecurve=false; Whether to use small dots//$Verify->usenoise=true; Verification code Width//$Verify->imagew=500; Verification code Width//$Verify->imageh=200; Verify number of code bits//$Verify->length=3; Set the interference color//$Verify->bg=array (255,0,0); Set verification code Character set///$Verify->codeset= "123456789"; Set field//$Verify->fontttf= "Simkai.ttf"; Set font//$Verify->zhset= "I love You"; Use Chinese captcha//$Verify->usezh=true; $Verify->entry (); $Verify=New\think\verify (); $Verify->fonotttf = "Simkai.ttf"; $Verify->zhset= "I Love You China"; $Verify->length=3; $Verify->usezh =true; $Verify-entry (); } functionCheck_verify ($code,$id= ' '){ $verify=New\think\verify (); return $verify->check ($code,$id); }
Public functionyzm1 () {if(is_post) {#code ...//echo "<pre>"; Print_r ($_session); echo "</pre>"; Pass the user's value for detection if($this->check_verify ($_post[' Code '])) { Echo"1"; }Else{ Echo"2"; } }Else{ $this-display (); } }}
Note: The Chinese captcha must be placed in the font path to Thinkphp/verify/zhttfs
Verification code correct echo 1;
Verification code error echo 2;
thinkphp Verification Code