ThinkPHP之登入驗證

來源:互聯網
上載者:User

標籤:

我比較懶,估計寫的不是很完整 

<?php/** * Created by dreamcms. * User: Administrator * Date: 2016/9/5 * Time: 17:15 */namespace Admin\Controller;use Think\Controller;class LoginController extends  CommonController{    //視圖顯示    public function Login(){        $this->display();    }    /**     * 登入驗證     */    public  function Check_Login(){        //驗證碼檢測       $names=$_POST[‘Captcha‘];        if($this->check_verify($names)==false){            $data[‘error‘]=1;            $data[‘msg‘]="驗證碼錯誤";            $this->ajaxReturn($data);        }        //使用者檢測        $uname=I(‘post.username‘);        $upasswd=I(‘post.password‘);        $map[‘uname‘]=$uname;        $map[‘state‘]=1;        $logins=M(‘login‘)->where($map)->find();        if($logins)        {            if($logins[‘upasswd‘]!=$upasswd)            {                $data[‘error‘]=1;                $data[‘msg‘]="密碼錯誤";                $this->ajaxReturn($data);            }            session("admin",$logins);            var_dump($logins);           redirect(U(‘Index/index‘));        }    }    /**     * 驗證碼產生     */    public  function Verifys()    {        $config=array(            ‘fontSzie‘=>30, //驗證碼字型大小            ‘length‘=>4,//驗證碼位元            ‘useImgBg‘=>true        );        $verify=new \Think\Verify($config);        $verify->useZh=true;        $verify->zhSet="夢起軟體工作室";        $verify->fontttf=‘simhei.ttf‘;        $verify->entry();    }    /**     * 驗證碼檢測     */    public  function check_verify($code,$id="")    {        $verify=new \Think\Verify();        return $verify->check($code,$id);    }    /**     * 退出登入     */    public  function out_login(){        session("admin",null);        redirect(U(‘Login/login‘));    }}

  前台頁面

<html><!DOCTYPE html><html lang="en" class="no-js"><head>    <meta charset="utf-8">    <title>登入(Login)</title>    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <meta name="description" content="">    <meta name="author" content="">    <!-- CSS -->    <link rel="stylesheet" href="__PUBLIC__/admin/login/css/reset.css">    <link rel="stylesheet" href="__PUBLIC__/admin/login/css/style.css">    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->    <!--[if lt IE 9]>    <script src="__PUBLIC__/admin/login/js/html5.js"></script>    <![endif]--></head><style>    * { margin:0; padding:0; }    body { background:#111; height:100%; }    img { border:none; }    #supersized-loader { position:absolute; top:50%; left:50%; z-index:0; width:60px; height:60px; margin:-30px 0 0 -30px; text-indent:-999em; background:url("__PUBLIC__/admin/login/img/progress.gif") no-repeat center center;}    #supersized {  display:block; position:fixed; left:0; top:0; overflow:hidden; z-index:-999; height:100%; width:100%; }    #supersized img { width:auto; height:auto; position:relative; display:none; outline:none; border:none; }    #supersized.speed img { -ms-interpolation-mode:nearest-neighbor; image-rendering: -moz-crisp-edges; }/*Speed*/    #supersized.quality img { -ms-interpolation-mode:bicubic; image-rendering: optimizeQuality; }/*Quality*/    #supersized li { display:block; list-style:none; z-index:-30; position:fixed; overflow:hidden; top:0; left:0; width:100%; height:100%; background:#111; }    #supersized a { width:100%; height:100%; display:block; }    #supersized li.prevslide { z-index:-20; }    #supersized li.activeslide { z-index:-10; }    #supersized li.image-loading { background:#111 url("__PUBLIC__/admin/login/img/progress.gif") no-repeat center center; width:100%; height:100%; }    #supersized li.image-loading img{ visibility:hidden; }    #supersized li.prevslide img, #supersized li.activeslide img{ display:inline; }    #supersized img { max-width: none !important }</style><body><div class="page-container">    <h1>夢起工作室後台登入(Login)</h1>    <form action="{:U(‘Login/Check_Login‘)}" method="post">        <input type="text" name="username" class="username" placeholder="請輸入您的使用者名稱!">        <input type="password" name="password" class="password" placeholder="請輸入您的使用者密碼!">        <input type="Captcha" class="Captcha" name="Captcha" placeholder="請輸入驗證碼!"><img src="{:U(‘Login/Verifys‘)}" width="120" height="43" name="verify" style="position: relative; top: 20px;" />        <button type="submit" class="submit_button">登入</button>        <div class="error"><span>+</span></div>    </form></div><!-- Javascript --><script src="__PUBLIC__/admin/login/js/jquery-1.8.2.min.js" ></script><script src="__PUBLIC__/admin/login/js/supersized.3.2.7.min.js" ></script><script src="__PUBLIC__/admin/login/js/supersized-init.js" ></script><script src="__PUBLIC__/admin/login/js/scripts.js" ></script></body></html>

  

 

ThinkPHP之登入驗證

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.