The above PHP background login code implements login-free

Source: Internet
Author: User
The following PHP background login code is free of logon. if the background administrator account is admin and the password is 123456, how can I implement login-free access using the following code, thank you for your PHPcode ;? PhpclassLoginActionextendsBaseAction {default operation publicfunctionindex () {if ($ the following PHP background login code to achieve login-free
If the background administrator account is admin and the password is 123456, could you tell me how to implement login-free using the following code? thank you!


PHP code
  
  Display (APP_PATH. '/Public/admin/login.html');} // Generate the verification code public function vcode () {import ("ORG. util. image "); Image: buildImageVerify (); // 6, 0, 'PNG ', 'verify'} // logon detection public function check () {if (empty ($ _ POST ['User _ name']) {$ this-> error ('account is required! ');} If (empty ($ _ POST ['User _ pwd']) {$ this-> error ('password required! ');} If (function_exists ('gd _ info') {if (empty ($ _ POST ['verify']) {$ this-> error ('verification code is required! ');} If ($ _ SESSION ['verify']! = Md5 ($ _ POST ['verify ']) {$ this-> error ('verification code error! ') ;}} // Generate the authentication condition $ map = array (); // bind an account to log on to $ map ['admin _ name'] = $ _ POST ['User _ name']; // $ map ["user_status"] = array ('GT ', 0); // status $ rs = D ("Admin. admin "); $ authInfo = $ rs-> where ($ map)-> find (); // use the username, password, and status to authenticate if (false ===$ authInfo) {$ this-> error ('account does not exist or has been disabled! ');} Else {if ($ authInfo ['admin _ pwd']! = Md5 ($ _ POST ['User _ pwd']) {$ this-> error ('incorrect password! ');} // Cache access permission $ _ SESSION [C ('User _ AUTH_KEY')] = $ authInfo ['admin _ id']; $ _ SESSION ['admin _ OK '] = $ authInfo ['admin _ OK']; $ _ SESSION ['admin _ name'] = $ authInfo ['admin _ name']; // $ _ SESSION ['email '] = $ authInfo ['admin _ email']; // $ _ SESSION ['lastlogintime'] = $ authInfo ['admin _ logintime']; // $ _ SESSION ['login _ count'] = $ authInfo ['admin _ count']; // if ($ authInfo ['User _ name'] = 'admin') {// $ _ SESSION ['admin'] = true ;//} // Save the logon information $ ip = get_client_ip (); $ data = array (); $ data ['admin _ id'] = $ authInfo ['admin _ id']; $ data ['admin _ logintime'] = time (); $ data ['admin _ count'] = array ('Exp ', 'admin _ count + 1 '); $ data ['admin _ IP'] = get_client_ip (); $ rs-> save ($ data); redirect ('index. php? S = Admin-index') ;}// the USER logs out of the public function logout () {if (isset ($ _ SESSION [C ('User _ AUTH_KEY ')]) {unset ($ _ SESSION [C ('User _ AUTH_KEY ')]); unset ($ _ SESSION); session_destroy (); $ this-> assign ('jumpurl ', 'index. php? S = Admin-Login '); $ this-> success ('logout successful! ');} Else {$ this-> error (' logged out! ') ;}}?>


------ Solution --------------------
Rewrite the index method
PHP code
    public function index(){        if ($_SESSION[C('USER_AUTH_KEY')]){            redirect("index.php?s=Admin-Index");        }        //$this->display(APP_PATH.'/Public/admin/login.html');            $_POST['user_name'] = 'admin';        $_POST['user_pwd'] = '123456';        $_POST['verify'] = 1;        $_SESSION['verify'] = md5($_POST['verify']);        $this->check();   }

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.