<?php
	header("Content-type:text/html;charset=utf-8");
	include("../include/conn_1.php");
	include("../include/function.php");
	include("../include/public.php");

	session_start();
	if ($action=="login")
	{
		
		if(trim($username)=='') die(json_encode(array('failure'=>false,'response'=>"请输入账号")));
		if(trim($password)=='') die(json_encode(array('failure'=>false,'response'=>"请输入密码")));
		
		// if ($verifycode!=$_SESSION["code_2"]) {
		// 	die(json_encode(array('failure'=>false,'response'=>"验证码错误")));
		// }
		$password = mymd5($password);
		$check_ary = array(" ","'","OR","and","AND","%","union","UNION","join","JOIN",";","\%","{","}","\$","=","/","\\","|","||");
		$username = str_replace($check_ary,"",$username);
		$sql_lgn = "select * from {$db_prefix}member where (username='".$username."' or mobile='".$username."') and pwd = '".trim($password)."'";
		$rs_lgn=$db->get_one($sql_lgn);
		$log_type=9;
		$log_addtime=time();
		$log_ip=getip();
		if(empty($rs_lgn["id"])) {
			setlogstype(0,$username,$log_type,$log_addtime,$log_ip,'会员登陆',0);
			die(json_encode(array('failure'=>false,'response'=>"您输入账号或密码错误")));
		}
		if($rs_lgn['state']!=='1') {
			setlogstype($log_adminid,$log_admin,$log_type,$log_addtime,$log_ip,'会员登陆',0);
			die(json_encode(array('failure'=>false,'response'=>"您的账号已经被禁止登陆")));
		}

		//if(!$rs_lgn['isactive']) die(json_encode(array('failure'=>false,'response'=>"您的账号还未激活")));
		
		$_SESSION["glo_userid"]  =$rs_lgn["id"];
		$_SESSION["glo_username"]=$rs_lgn["username"];

		$db->query("update {$db_prefix}member set logintime='".time()."',lognum=lognum+1 where id='".$rs_lgn['id']."'");
		$log_adminid=$_SESSION["glo_userid"];
		$log_admin=$_SESSION["glo_username"]; 
		$log_type=9;
		$log_addtime=time();
		$log_ip=getip();

		setlogstype($log_adminid,$log_admin,$log_type,$log_addtime,$log_ip,'会员登陆',1);
		die(json_encode(array('failure'=>true,'response'=>"登陆成功")));
	}

	//注销
	if ($action=="loginout"){
		$_SESSION["glo_userid"]='';
		$_SESSION["glo_username"]=''; 
		session_destroy();
		header("location:/mobile/index.php");
		exit();
	}
?>