<?php
session_start();
include "conn/config.php";

//登陆判断
if($_POST['sub']){
  $username = trim($_POST['username']);
  $pass = md5(trim($_POST['pass']));
  
  //判断用户名是否为空
  if($username == ""){
	  echo "<script type='text/javascript'>alert('用户名不能为空！');history.go(-1);</script>";
  }
  
  //判断密码是否为空
  if($pass == ""){
	  echo "<script type='text/javascript'>alert('密码不能为空！');history.go(-1);</script>";
  }
  
  //访问数据库
  $query = mysql_query("select * from {$total_pr}user where username='".$username."'");
  while($rows = mysql_fetch_assoc($query)){
	  $rank = $rows['rank'];
	  $rpass = $rows['password'];
	  $rid = $rows['id'];
  }
	  if(mysql_num_rows($query) == 0 ){
		  echo "<script type='text/javascript'>alert('该用户不存在！');history.go(-1);</script>";	
	  }
	  
	  if($rank == '000'){
		  echo '<script type="text/javascript">alert("由于某种原因，您的账号已被封锁，请与管理员联系（QQ:578672331）!");history.back();</script>';
	  }
	  else{
		  if($rpass != $pass){
			  echo "<script type='text/javascript'>alert('密码输入错误！');history.go(-1);</script>";
		  }
		  else{
			  $_SESSION['user_id'] = $rid;
			  header("location:index.php?id=$rid");	
		  }
	  
     }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="css/lo_re.css" />
<link type="text/css" rel="stylesheet" href="css/jquery.ui.datepicker.css" />
<link type="text/css" rel="stylesheet" href="css/jquery.ui.theme.css" />
<script type="text/javascript" language="javascript" src="js/jquery-1.5.1.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.ui.datepicker-zh-CN.js"></script>
<title>博客登陆</title>
<script type="text/javascript">

   function check_login(form){
	  if(form.username.value == ""){
		alert("用户名不能为空！");
		form.username.select();
		return false;  
	  }
	  
	  if(form.pass.value == ""){
		alert("密码不能为空！");
		form.pass.select();
		return false; 
	  }
	  
	  return true;   
   }
</script>
</head>

<body>
<div id="login">
   <div class="login_title">
     <h5>尘烟博客登陆</h5>
   </div>
   <div class="login_con">
     <div class="con">
      <form action="login.php" method="post" name="form1" onsubmit="return check_login(this);">
        <table>
          <tr>
            <td>
              <label for="username">账户：</label>
              <input type="text" name="username" id="username" />
            </td>
          </tr>
          <tr>
            <td>
              <label for="pass">密码：</label>
              <input type="password" name="pass" id="pass" />
            </td>
          </tr>
          <tr>
            <td>
              <input type="submit" class="submit" name="sub" value="登陆"/>
              <input type="button" class="register" value="注册" onclick="window.location='register.php'">
            </td>
          </tr>
        </table>
      </form>
     </div>
    </div>
    <div class="login_footer">
      <div class="left"><img src="images/lo_re__footer_left.gif" /></div>
      <div class="bg"></div>
      <div class="right"><img src="images/lo_re_footer_right.gif" /></div>
    </div>
</div>
</body>
</html>