您当前的位置: 首页 > 学无止境 > 网站建设 网站首页网站建设
thinkphp登录判断与分帧使用
发布时间:2016-01-09 09:13:59编辑:雪饮阅读()
index模块判断当前帐号是否登录并予以处理:
<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
if(isset($_SESSION["username"]) && $_SESSION["username"]!=""){$this->display();}
else{redirect('Login/login');}
}
public function top(){
$this->display();
}
public function left(){
$this->display();
}
public function right(){
$this->display();
}
}
登录模版:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<load href="__PUBLIC__/css/basic.css"/>
<load href="__PUBLIC__/css/login.css"/>
<load href="__PUBLIC__/js/jquery-1.11.1.min.js"/>
<script>
$(function(){
$('img[title="login"]').click(function(){
$('form[name="myform"]').submit();
});
});
</script>
</head>
<body>
<form action="__URL__/dologin" method="post" name="myform">
用户名:<input type="text" name="username"/><br/>
密 码:<input type="password" name="password"/><br/>
验证码:<input type="text" name="code"><img src="__APP__/Public/code" onClick="this.src=this.src+'?'+Math.random()"/><br/>
<img src="__PUBLIC__/images/login.gif" title="login" class="submit"/>
<img src="__PUBLIC__/images/register.gif" />
</form>
</body>
</html>
登录模块:
<?php
// 本类由系统自动生成,仅供测试用途
class LoginAction extends Action {
public function login(){
$this->display();
}
public function dologin(){
$username=$_POST["username"];
$password=$_POST["password"];
$code=$_POST["code"];
if(md5($code)!=$_SESSION["code"]){
$this->error("验证码不正确");
}
$m=M("User");
$where["username"]=$username;
$where["password"]=$password;
$arr=$m->field('id')->where($where)->find();
if($arr){
$_SESSION["username"]=$username;
$_SESSION["id"]=$arr["id"];
$this->success("用户登录成功",U("Index/index"));
}
else{
$this->error("当前用户不存在");
}
}
}
Top方法所在模版(left和right直接先改名字即可):
验证码模块:
第一个参数是验证码数字的位数此处设置为2位
第二个参数是验证码的模式:
验证字符串的类型,默认为数字,其他支持类型有0 字母 1 数字 2 大写字母 3 小写字母 4中文 5混合
第三、四参数为验证码的宽、高
第五个参数为验证码的session名称
首页模版(分帧的使用):
分帧使用时无需body标签了,直接用frameset标签,rows属性按照上下来分
Rows=”20%,*”代表上部分20%,
Cols按照左右分,cols=”50%,50%”代表左右均分50%:
关键字词:thinkphp,登录,分帧