这个login首页
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<head>
<title>login</title>
<load href="__PUBLIC__/Js/jquery.js"/>
<load href="__PUBLIC__/Css/basic.css"/>
<script>
$(function(){
$("img[title='login']").click(function(){
$('form[name="myform"]').submit();
});
});
</script>
<style>
</style>
</head>
<body>
<form action="__URL__/dologin" method="post" name="myform">
用户名:<input type="text" name="username" /><br/>
密 码:<input type="password" name="passeord" /><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>
这个是Thinkphp中的控制器(login方法)
<?php
class LoginAction extends action{
public function login(){
$this->display();
}
public function dologin(){
//dump($_POST);//接受值
//判断用户在数据库中是否存在
//存在 允许登陆
//不存在 显示错误信息
$username=$_POST['username'];
$password=$_POST['password'];
$code=$_POST['code'];
//如果$code不等于$_SESSION['code']
if(md5($code)!=$_SESSION['code']){
$this->error('验证码不正确');
}
$user=M("user");
$where['username']=$username;
$where['password']=$password;
$arr=$user->where($where)->find();
dump($arr);
//exit;//暂停
if($count>0){
$_SESSION['username']=$username;
$_SESSION['id']=$arr['id'];
$this->success('用户登陆成功',U('index/index'));
}else{
$this->error('该用户不存在');
}
}
}
?>
这个是数据库