thinkphp3.2.3--Login and Exit login ____php

Source: Internet
Author: User
One login LoginController.class.php:
    Public Function Index () {
        $admin =d (' admin ');//materialized Database
        if (is_post) {
            if ($admin->create ($_post,4)) {// Verify the input: username/password/authentication code
                if ($admin->login ()) {
                    $this->success (' login succeeded. Jump ... ', U (' Index/index ');//You can also jump directly to
                }else{
                    $this->error ("username or password does not exist.") ");
                }
            } else{
                $this->error ($admin->geterror ());
            }
            return;
        }
        if (session (' ID ')) {
            $this->error (' You are logged in, do not log on again. ', U (' Index/index ');
        } else{
            $this->display ();
        }
    
AdminModel.class.php:
<?php namespace Admin\model;
Use Think\model; Class Adminmodel extends Model {protected $_validate = Array (' username ', ' require ', ' admin name must not be empty. ', 1, ' Regex ', 3,///By default verify Array (' username ', ', ', ', ', ' admin name already exists. ', 1, ' Unique ', 3, Array (' Password ', ' Require ', ' password must not be null. ', 1, ' regex ', 1,//above is registered when verifying//below is login authentication Array (' username ', ' require ', ' admin name must not be empty. ', 1, ' Regex ', 4, Array (' Password ', ' Require ', ' password must not be null. ', 1, ' Regex ', 4, Array (' Verify ', ' check_verify ', ' captcha error.

    ', 1, ' Callback ', 4);
        Public Function Login () {$password = $this->password;
        $info = $this->where (Array (' username ' => $this->username))->find ();
                if ($info) {if ($info [' Password ']==md5 ($password)) {session (' ID ', $info [' id ']);
                Session (' username ', $info [' username ']);
            return true;
        }}else{return false; }} Public Function check_verify ($code, $id = ') {$verify =new \think\verify ();
    Return $verify->check ($code, $id); }
}
Two sign out
    Public Function Logout () {session
        (NULL);
        $this->success (' Exit succeeded. Jump in ... ', U (' Login/login '));
    }

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.