<?php
/*
 * Ourphp - CMS建站系统
 * Copyright (C) 2014 ourphp.net
 * 开发者：哈尔滨伟成科技有限公司
 *-------------------------------
 * IP接口
 *-------------------------------
*/
if(!defined('OURPHPNO')){exit('no!');}
if(getenv('HTTP_CLIENT_IP')) { 

	$onlineip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR')) { 

	$onlineip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR')) { 

	$onlineip = getenv('REMOTE_ADDR');
} else {
	$onlineip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
}

if(empty($_SESSION['ourphp_ip']))
{
	if($onlineip != '127.0.0.1'){
		
		$host = "https://c2ba.api.huachen.cn";
		$path = "/ip";
		$method = "GET";
		$appcode = $api[2];
		$headers = array();
		array_push($headers, "Authorization:APPCODE " . $appcode);
		$querys = "ip=".$onlineip;
		$bodys = "";
		$url = $host . $path . "?" . $querys;

		$curl = curl_init();
		curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($curl, CURLOPT_FAILONERROR, false);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_HEADER, false);
		if (1 == strpos("$".$host, "https://"))
		{
			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
		}
		curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
		$ipinfo = curl_exec($curl);
		$ipinfo = json_decode($ipinfo,true);
		$taobaoip = $ipinfo['data']['region'];
		$_SESSION['ourphp_ip'] = $taobaoip;

	}else{
		$taobaoip = '本地IP';
	}
	
}else{
	
	$taobaoip = $_SESSION['ourphp_ip'];
}

?>