ThinkPHP之登录验证
验证方面写的不是很完整,正在完善当中
<?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>