Home > Backend Development > PHP Tutorial > 这个登录模块咋回事

这个登录模块咋回事

WBOY
Release: 2016-06-13 10:03:00
Original
911 people have browsed it

这个登录模块怎么回事?
数据库明明有东西就是读不出来 真是晕了 源代码在下面: 总是显示账号密码错误 哎 
//判断用户是否已经登陆
session_start();
if(!empty($_SESSION['username']))
{
echo "您已经登录了页面!";
exit;
}
//echo "您好,".$_SESSION['username'];
?>
require_once('check.php'); //引入公共文件,实现检查用户输入,防止SQL注入漏洞的代码
//trim()函数可以截取头尾的空白字符
$username = trim($_POST['username']);
$pwd = md5($_POST['pwd']);


//设置一个错误变量,以便检查错误
$errmsg = '';
if(empty($username)||empty($_POST['pwd']))
{
  $errmsg = '输入数据不完整';
  
}
if(!empty($username)&&empty($errmsg))
{


  include_once(conn.php);
  if(!$conn)
  {
  $errmsg = "数据库连接错误";
  }
  //$sql=mysql_query("select * from tb_yonghu");
  $sql=mysql_query("select * from tb_yonghu where name='$username' and password='$pwd'");
  $info=mysql_fetch_array($sql);
  $row=mysql_num_rows($sql);
  if(!$row){
  $errmsg = "账号或密码错误";
  }
  else{
   
  //使用session保存当前用户
  session_start();
  $_SESSION['username'] = $username;
   
  //在实际应用中可以使用前面提到的重定向功能转到主页
  $errmsg = "登录成功!";
  //更新用户登陆信息
  $ip = $_SERVER['REMOTE_ADDR']; //获取客户端的IP
  $sql = "update tb_yonghu set f_logintimes=f_logintimes+1,f_lasttime=now(),f_loginip='$ip' where name='$username'";
  mysql_query($sql);
  }
   
  //关闭数据库连接
  mysql_close($conn);
  }

?>


 
  User Login
 
  
 
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template