First understand some of the functions in the parent class Verity.class.php (thinkphp/library/think/verity.class.php)
1:check () Verify that the verification code is correct
2:entry () output The verification code and save the value of the verification code in the session
3:authcode () Encryption Verification code (this method is called in the Check () method)
The controller generates the CAPTCHA code:
//Verification Code functionverifyimg () {//Verification Code Configuration $cfg=Array( ' Imageh ' = 30,//Verification Code Picture height' Imagew ' = 100,//Verification Code Picture width' FontSize ' = 15,//captcha font size (px)' Length ' = 4,//Verify number of code bits' Fontttf ' = ' 4.ttf ',//captcha font, not set random get ); //instantiate the Verify class to automatically call the constructor and pass the $cfg information to $config $verify=NewVerify ($cfg); $verify-entry();//Output Verification Code}
Verification code displayed at front desk
<!-- Group/Controller/method --
<src= "<{$smarty. const.__controller__}>/verifyimg" = "this.src= ' <{$smarty. const.__controller__}>/verifyimg/' +math.random ()" alt = "Verification Code" />
Controller calibration Code (take login as an example)
//Login functionLogin () {//two logic: show, collect if(!Empty($_post)) { $verify=NewVerify (); //Receive Verification Code $captcha=$_post[' Captcha ']; //Check () method check Verification code if($verify-Check($captcha)) { EchoCorrect; }Else{ EchoError; } } //call The View view $this-display (); }
Use thinkphp to implement build/verify Captcha function