<?php
	//设置上线时间 $webstartdate，生成 手机banner_S
	require_once('_approot.php');	
	
	$username=inputsafe(trim($_POST['username']));
	$password=inputsafe(trim($_POST['password']));
	$passRetryTimes=8; //最大重试密码次数
	$passdelaytime=1800; //重试间隔时间 30分钟
	$code=$_SESSION["code"];
	
	if(!isset($_SESSION['passTimes']))
	{$_SESSION['passTimes']=0;}

	if(!isset($_SESSION['startTimes']))
	{$_SESSION['startTimes']=0;}
?>
<!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>
<title><?=$engineName?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
	<?php 	$_SESSION['passTimes']++;

	if($_SESSION['passTimes']>$passRetryTimes)   //超过规定次数进行验证码验证
	{
		if($_SESSION['startTimes']==0){$_SESSION['startTimes']=time();}
		$waittime=$_SESSION['startTimes']+$passdelaytime-time();
		if($waittime>0){ 
			echo "<script>
				alert('错误连续超过".$passRetryTimes."，请".(round($waittime/60))."分钟后再试'); 
				location='index.php';	
			</script>";
			 
		}else{
			$_SESSION['startTimes']=0;  //重置
			$_SESSION['passTimes']=0;
		}
	}
	
		if(strpos($username,"'")!==false || strpos($username,'"')!==false )
		{
			echo 	"<script>
							alert('您的账号和密码不能为空  ！'); 
							location='index.php';	
						</script>";
		}
		
		
		if(empty($username) || empty($password))
		{
			echo 
						"<script>
							alert('您的账号和密码不能为空！'); 
							location='index.php?username=".$username."';	
						</script>";
		}
	  else
	  {
			$sqlstr="select * from ls_admin where  adminName='".$username."'";
			
			
			$query1=$opendb->query($sqlstr);
			$rows=mysqli_fetch_assoc($query1);
			$myrows=mysqli_num_rows($query1); 
			if($myrows==0)
			{
				$_SESSION['retryTimes']++;
				echo "
						
						<script>
							alert('对不起，用户名或密码不正确 ！');
							location='index.php?username=".$username."';	
						</script>
						";
			}
			if(md5($password)!=$rows['adminPwd'] || $username!='admin')
			{
				$_SESSION['retryTimes']++;
				echo "
						<script>
							alert('对不起，用户名或密码不正确！');
							location='index.php?username=".$username."';		
						</script>
						";
			} 
		else
		{
			if($_SESSION['retryTimes']>$codeRetryTimes)   //超过规定次数进行验证码验证
			{
				if($_POST['code']=="")
				{
					echo "<script>
								alert('请输入验证码！'); 
								location='index.php?username=".$username."';	
							</script>";
				}
				if(strtoupper($_POST['code'])!=$_SESSION["code"])
				{
					echo "<script>
								alert('验证码错误！'); 
								location='index.php?username=".$username."';	
							</script>";
				}else{ //成功2？
					
					writelog($_SERVER['PHP_SELF'],"login: ".$username,"retryTimes: ".($_SESSION['retryTimes']-1),$username);
					$_SESSION['retryTimes']=0;  
					$_SESSION['inputTimeOut']=time();
					$_SESSION['username']=$username;
					$_SESSION['passTimes']=0;
					$_SESSION['startTimes']=0;  //重置
					$myurl=$_SERVER['PHP_SELF'];
					if( !$ls_local && $webstartdate=="" && strpos($myurl,"/new/")===false && strpos($myurl,"slatestones.cn")===false && strpos($myurl,"lanscend.cn")===false) writeconstant("webstartdate", date("Y-m-d")); //设置上线日期

					file_exists("_create_banner_s.php")?include  "_create_banner_s.php" :"" ; 

				
					//$_SESSION['password']=$password;
					//header("location:all.php");	
					// require_once('../update/updatels.php');  
					echo "	<script>location='all.php';</script>";
				}
			}else{ //成功
				writelog($_SERVER['PHP_SELF'],"login: ".$username,"retryTimes: ".($_SESSION['retryTimes']-1),$username);
				$_SESSION['retryTimes']=0;
				$_SESSION['inputTimeOut']=time();
				$_SESSION['username']=$username;
					
				$_SESSION['passTimes']=0;
				$_SESSION['startTimes']=0;  //重置
				$myurl=$_SERVER['PHP_SELF'];
				if( !$ls_local && $webstartdate=="" && strpos($myurl,"/new/")===false && strpos($myurl,"slatestones.cn")===false && strpos($myurl,"lanscend.cn")===false)  include "_webonline.php"  ; //上线初始化操作
				
				file_exists("_create_banner_s.php")?include  "_create_banner_s.php" :"" ; //手机banner图片处理
				 
				echo "	<script>location='all.php';</script>";
			}
		}
		
	  }
  
?>

<body>
</body>
</html>