1<?PHP2 3 namespace Model;4 5 UseThink\model;6 7 classUsermodelextendsModel {8 9 functionChecknamepwd ($mg _name,$mg _password) {Ten //instantiating a model user One $user= M ("User"); A //receive the data transmitted by the Controller to determine whether it is consistent. and return - $info=$user->getby_mgname ($mg _name); - //if the name attribute data exists, the corresponding password is determined to be consistent and returned. the if($info!=NULL) { - //Verify Password - if($info[' mg_password '] = =$mg _password) { - return $info; +}Else { - return false; + } A}Else { at return false; - } - } - - } - in?> - to + - the * $ Panax Notoginseng<?PHP - the //name Space + A namespace Home\controller; the + UseThink\controller; - $ classUsercontrollerextendsController { $ - //Login - functionLogin () { the if(!Empty($_post)) { - Wuyi //Verification Code the //Instantiate the Verify class of the thinkphp3.2 framework and make judgments. - Wu $verify=New\think\verify (); - if(!$verify->check ($_post[' Captcha '])) { About //Check the verification code $ //I (' id ', 0); get ID parameter automatically judge get or post I (' Post.name ', ' ', ' htmlspecialchars '); - //Get $_post[' name '] I (' get. '); get $_get - $verify= I (' param.verify ', ' '); - if(!check_verify ($verify)) { A $this->error ("Pro, the verification code is wrong!") ",$this->site_url, 1); + } the}Else { - //Instantiate model $ $user=New\model\usermodel (); the $rst=$user->checknamepwd ($_post["Mg_name"],$_post["Mg_password"]); the //= = All equals the if($rst===false) { the Echo' User name or password error '; -}Else { inSession ("Mg_name",$rst[' Mg_name ']); the theSession ("mg_id",$rst[' mg_id ']); About //jump page, in the controller directly using the redirect () method to jump the $this->redirect (' Index/index ', 0); the } the } + } - $this-display (); the }Bayi the //Exit System the functionloginout () { -SessionNULL); - $this->redirect (' User/login ', 0); the } the the //Create a verification code the functionverifyimg () { - //set the style of the captcha the $config=Array( the' Imageh ' = 25,//Verification Code Picture height the' Imagew ' = 120,//Verification Code Picture width94' Fontttf ' = ' 4.ttf ',//captcha font, not set random get the' Length ' = 4,//Verification Code Length the' FontSize ' = 14,//captcha font size (px) the );98 $verify=New\think\verify ($config); About //Create Validation - $verify-entry ();101 }102 103 //"Empty Operation" This method is used for friendship tips! 104 function_empty ($param) { the Echo' Sorry, this method does not exist! ‘;106 }107 108 }109 the?>111 the 113 the<script type= "Text/javascript" > the /*get pictures of captcha_img*/ the varcaptcha_img = $ ('. User_main_input '). FIND (' img '));117 //return captcha_img src118 varverifyimg = captcha_img.attr ("src");119Captcha_img.attr (' title ', ' Click to Refresh '); - //Click events121Captcha_img.click (function() {122 if(Verifyimg.indexof ('? ') > 0) {123 124 //&random= Stitching Verification Code Picture the$ (this). attr ("src", verifyimg + ' &random= ' + Math.random ());126}Else {127$ (this). attr ("src", Verifyimg.replace (/\). *$/, ') + '? ' + Math.random ()); - }129 }); the</script>131 the 133 134 135 136 137<?PHP138 139The function under the common file.PHP (New) $ /**141 * Verification Code Check142 * Add global function143 */144 functionCheck_verify ($code,$id= "") {145 $verify=New\think\verify ();146 return $verify->check ($code,$id);147 }148?>149 Max
thinkphp3.2 Implementation Login + verification code