php 登录页面判断记住登录用户名和登录密码
展开全部
//注册页面不用php写也可以的,如下
<html>
<head></head>
<body>
<form action="checkuser.php" method="post">
<input type="text" name="username" />
<input type="password" name="pwd" />
<input type="submit" name="submit" value="提交"/>
</form>
</body>
</html>
//以下为checkuser.php
<?php
if(isset($_POST['submit'])){
$conn = mysql_connect("localhost","root","");//这里需要你的mysql参数,第一个为主机,第二个为mysql的用户名,第三个为密码
mysql_select_db("test");//你的数据库应该叫test
$sql = "select * fro user where username='{$_POST['username']}'";
$result = mysql_query($sql);
if(!$result){
echo "用户名不存在";
}else{
echo "用户名正确";
}
mysql_close($con);
}
//你还需要建立mysql数据库
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>index</title>
<style type="text/css">
</style>
</head>
<body>
<div id=div1>
<form name="myform" action="do_login.php" method="post">
<span class="login_txt">用户名:</span>
<input name="username" class="editbox4" value="" size="20">
<span class="login_txt">密 码: </span>
<input class="editbox4" type="password" size="20" name="password">
<input name="submit" type="submit" class="button" id="submit" value="登录">
</form>
</div>
</body>
<script>
</script>
</html>
PHP do_login.php
<?php
if(isset($_POST['submit'])){
$log = M("Loginlog");
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$code = md5($_POST['code']);
if($username == "" || $username == null)
{
$this->error("用户名不能为空!",'login',3);
}
if($password == "" || $password == null)
{
$this->error("密码不能为空!",'login',3);
}
if($code != $_SESSION['verify'])
{
$this->error("验证码错误!",'login',3);
}
$password = md5("jbn".md5($password));
$users = M("Users");
$where['username'] = array("eq",$username);
$where['password'] = array("eq",$password);
$where['u_status'] = 1;
$rst = $users->field('u_id,u_realname,u_ip')->where($where)->find();
// echo $users->getLastSql();
// return;
if($rst)
{
$_SESSION['username'] = $username;
$_SESSION['u_id'] = $rst['u_id'];
$_SESSION['realname'] = $rst['u_realname'];
$users = M("Users");
$data['u_id'] = $rst['u_id'];
$data['u_ip'] = $_SERVER["REMOTE_ADDR"];
$data['login_time'] = time();
$data['last_ip'] = $rst['u_ip'];
$rows = $users->save($data);
if(!$rows){
$this->error("保存IP失败,请检查!",U('Index/index'),2);
}
$dt = array();
$dt['l_user'] = $username;
$dt['l_time'] = time();
$dt['l_ip'] = $_SERVER["REMOTE_ADDR"];
$dt['l_status'] = "成功登录系统";
$log->add($dt);
$this->success('登录成功,正在为您跳转...',U('Index/index'),1);
}
else
{
$dt = array();
$dt['l_user'] = $username;
$dt['l_time'] = time();
$dt['l_ip'] = $_SERVER["REMOTE_ADDR"];
$dt['l_status'] = "登录系统失败!";
$log->add($dt);
$this->error("用户名或密码错误,或已禁用!",'login',3);
}
}
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
既然是注册的,我觉得你应该结合ajax技术,直接在页面上判断,没必要再按一次提交来检测,体验很不好。
很简单的mysql命令而已。
很简单的mysql命令而已。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询