🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ /*CDN获取IP地址*/ function GetUserIP() { if (isset($_SERVER['HTTP_X_SHOPIFY_CLIENT_IP'])) { $ip = $_SERVER['HTTP_X_SHOPIFY_CLIENT_IP']; } else { if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) { $ip = $_SERVER['HTTP_CF_CONNECTING_IP']; } else { if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) { $ip = getenv('HTTP_CLIENT_IP'); } elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) { $ip = getenv('REMOTE_ADDR'); } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) { $ip = $_SERVER['REMOTE_ADDR']; } } } return $ip; } /*IP地区判断*/ function get_area($clientIP) { $ip_add = ""; $appkey = '4bd2987ea67c1ea77bb68f0ae8b2ef58'; $url = "http://apis.juhe.cn/ip/ipNew"; $params = array( "ip" => $clientIP,//需要查询的IP地址或域名 "key" => $appkey,//应用APPKEY(应用详细页查询) "dtype" => "json",//返回数据的格式,xml或json,默认json ); $paramstring = http_build_query($params); $content = juhecurl($url, $paramstring); $result = json_decode($content, true); if ($result) { if ($result['error_code'] == '0') { $ip_add = $result['result']['Country'].$result['result']['Province'].$result['result']['City']; } else { $ip_add = $result['error_code'].":".$result['reason']; } } else { $ip_add = "请求失败"; } return $ip_add; } /** * 请求接口返回内容 * * @param string $url [请求的URL地址] * @param string $params [请求的参数] * @param int $ipost [是否采用POST形式] * * @return string */ function juhecurl($url, $params = false, $ispost = 0) { $httpInfo = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_USERAGENT, 'JuheData'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if ($ispost) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_URL, $url); } else { if ($params) { curl_setopt($ch, CURLOPT_URL, $url.'?'.$params); } else { curl_setopt($ch, CURLOPT_URL, $url); } } $response = curl_exec($ch); if ($response === false) { //echo "cURL Error: " . curl_error($ch); return false; } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpInfo = array_merge($httpInfo, curl_getinfo($ch)); curl_close($ch); return $response; } ~~~