Kill lui lei Dog---thinkphp----log in after 10. Write-off one dragon

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.