<?
session_start();


include("../include/config.inc.php");
include("../include/function.php");


if(!session_is_registered("126cmscode"))
{
  exit("<center>验证码错误！<br><br><input type=button value=返回 onclick=history.back()></center>");
}

$postdb = $_POST['postdb'];

if( $postdb['code'] != $_SESSION['126cmscode']){
	exit("<center>验证码错误！<br><br><input type=button value=返回 onclick=history.back()></center>");
}
?>
<style type="text/css">
<!--
.fontRed {
	font-family: "宋体";
	font-size: 14px;
	color: #FF0000;
}
-->
</style>
<?
if ( !checkUser($postdb["userid"],$postdb["pwd"]) ){
	echo "<div align=\"center\" class=\"fontRed\">您输入的用户名或密码有误!<br><input type=button value=返回 onclick=history.back()></div>";
	exit;
}

$postdb["pwd"]=md5($postdb["pwd"]);


$query="SELECT * FROM `w6_admin` WHERE `userid` ='".$postdb["userid"]."'";
	
$result=mysql_query($query) or die("Could not connect: " . mysql_error());
	
$num = mysql_num_rows($result);
	
if( $num == 0 ){
	echo "<div align=\"center\" class=\"fontRed\">您输入的用户名或密码有误!<br><input type=button value=返回 onclick=history.back()></div>";
	exit;
}
	
$_pwd        =  stripslashes(mysql_result($result,"0","pwd"));
$gptype        =  stripslashes(mysql_result($result,"0","gptype"));
$adminid        =  stripslashes(mysql_result($result,"0","id"));
	

if( $postdb["pwd"] != $_pwd ){

	echo "<div align=\"center\" class=\"fontRed\">您输入的用户名或密码有误!<br><input type=button value=返回 onclick=history.back()></div>";
	exit;
	
}else{

	$logintime = time();
	$loginip   = GetIP();

	$query="UPDATE `w6_admin` SET `logintime`='".$logintime."' , `loginip`='".$loginip."' WHERE `id`=".$adminid; 

	$result = mysql_query($query) or die(mysql_error());
	
	if ($result){
		  
		  ///////开启session
          @session_register("126cmsadmindb");
          $_SESSION['126cmsadmindb']['adminid'] = $adminid;
          $_SESSION['126cmsadmindb']['gptype'] = $gptype;
          ///////开启session
          echo "<meta http-equiv=\"refresh\" content=\"0;URL=sys/\">";
          echo "<center>";
          echo "<a href='sys/'>";
          echo "如果没有自动跳转,请点击这里!";
          echo "</a>";
          echo "</center>";
		  
	}
		  
}
	  
	  
	  
	  
	  
	  
	  
	  
	  
	 /*
     *  检验用户是否正确
     */
    function checkUser($user, $pwd)
    {
	
		if( !$user || !$pwd ){
		
			return false;
			
		}else if(strlen($user) > 20){//用户名不能超过20位
		
			return false;
			
		}else{
			
			$f_key = '",\',\\,_admin,\(,\)';//用户名中不允许出现的非法字符
			$filter = explode(',',$f_key);
			for($i=0;$i < count($filter);$i++){
				if (preg_match ("/".$filter[$i]."/i",$user)){
					return false;
					break;
				}
			}
		}

			return true;

	}
	

?>
