First of all, we still write a controller name called LoginController.class.php Controller, first to write a code method to let the verification code first display:
Public functionCode () {//create an instance of the Captcha class $verify=New\think\verify (); //emptying the OB cache Ob_clean(); //Setting the initialization verification code $verify-CodeSet = "0123456789"; $verifyLength = "4"; $verify-FontSize = "30px"; $verify-Fonttf = "4.ttf"; $verify-Usecurve =false; $verify-Usenoise =false; //Show verification Code, and save in session $verify-entry (); //If you don't feel good, you can set it through the tplx\thinkphp\library\think\verify.class.php .}
Let the following in the login page to modify the code can be normal to run up again:
And then write more than a section of the JS code, so that the verification code can be changed when clicked,
<Divclass= "Login"> <H1>Login</H1> <formMethod= "POST"Action=""__url__/login/"> <inputtype= "text"name= "username"placeholder= "User name"Required= "Required" /> <inputtype= "Password"name= "Password"placeholder= "Password"Required= "Required" /> <inputtype= "text"name= "Captcha"placeholder= "Verification Code"Required= "Required" /> <imgID= "Code"src= "__controller__/code"width= "145"Height= " the"alt= "CAPTCHA"Border= "1"onclick= this.src= "index.php?act=captcha&" +math.random ()style= "Cursor:pointer;"title= "Can not see clearly?" Click Replace another verification code. " /> <Buttontype= "Submit"class= "btn btn-primary btn-block btn-large">Login</Button> </form></Div><Divstyle= "Text-align:center;"></Div><Script>window.onload= function() {document.getElementById ("Code"). onclick= function(){ This. SRC= "__url__/code/_/"+NewDate (). GetTime (); } }</Script></Body>
Then write a controller and let him verify the data submitted:
Large d is used here, so verify the account number and password in the model
<?php namespace Admin\model; UseThink\model; //Background Administrator Model classUsermodelextendsmodel{//Verify user name and password functionCheckUser ($username,$password){ $condition[' username '] =$username;//This is username when the database was designed. $condition[' password '] =MD5($password);//This is password when the database was designed. if($admin=$this->where ($condition),Find ()) { //success, save session, and jump to homepageSession (' admin ',$admin); return true; }Else{ return false; } } }
Let us successfully through the first verification verification code, verify the account number and password to sign in, the next step is to log out, this is also very simple,
// Logout Public function logout () { session (null); $this -Success (' Congratulations on successful exit ', ' Login/login ', 3); }
Let's modify the following link under the background model, as follows:
class= "Admin-out" > Logout </a>
Mainly add a piece of code:
Kill lui lei dog---thinkphp----log in after 10. Log out of one dragon