You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
51 lines
1.4 KiB
<?php |
|
//*API扩展文件*/ |
|
|
|
function getIP() { |
|
if (getenv('HTTP_CLIENT_IP')) { |
|
$ip = getenv('HTTP_CLIENT_IP'); |
|
} |
|
elseif (getenv('HTTP_X_FORWARDED_FOR')) { |
|
$ip = getenv('HTTP_X_FORWARDED_FOR'); |
|
} |
|
elseif (getenv('HTTP_X_FORWARDED')) { |
|
$ip = getenv('HTTP_X_FORWARDED'); |
|
} |
|
elseif (getenv('HTTP_FORWARDED_FOR')) { |
|
$ip = getenv('HTTP_FORWARDED_FOR'); |
|
} |
|
elseif (getenv('HTTP_FORWARDED')) { |
|
$ip = getenv('HTTP_FORWARDED'); |
|
} |
|
else { |
|
$ip = $_SERVER['REMOTE_ADDR']; |
|
} |
|
return $ip; |
|
} |
|
|
|
function curl($url) { |
|
$ip = getIP(); |
|
$curl = curl_init($url); |
|
|
|
#curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"); |
|
curl_setopt($curl, CURLOPT_FAILONERROR, true); |
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); |
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array('CLIENT-IP: '.$ip,'X-FORWARDED-FOR: '.$ip)); |
|
#设置超时时间,最小为1s(可选) |
|
curl_setopt($curl , CURLOPT_TIMEOUT, 5); |
|
|
|
$html = curl_exec($curl); |
|
curl_close($curl); |
|
return $html; |
|
} |
|
|
|
function err_msg($msg) { |
|
$data = [ |
|
'code' => 403, |
|
'err_msg' => $msg |
|
]; |
|
exit(json_encode($data)); |
|
} |