function
ip(
$ip
)
{
$url
=
"http://ip.taobao.com/service/getIpInfo.php?ip="
.
$ip
;
$ipinfo
=json_decode(
file_get_contents
(
$url
));
if
(
$ipinfo
->code==
'1'
){
return
false;
}
$city
=
$ipinfo
->data->region.
$ipinfo
->data->city;
return
$ipinfo
;
}
print_r(ip(
"123.116.154.35"
));
$ipinfo
= stdClass Object
(
[code] => 0
[data] => stdClass Object
(
[country] => 中国
[country_id] => CN
[area] => 华北
[area_id] => 100000
[region] => 北京市
[region_id] => 110000
[city] => 北京市
[city_id] => 110100
[county] => 西城区
[county_id] => 110102
[isp] => 联通
[isp_id] => 100026
[ip] => 123.116.154.35
)
)
/**
curl封装函数
*/
function
https_request(
$url
,
$data
=NULL){
$ch
= curl_init();
curl_setopt(
$ch
, CURLOPT_URL,
$url
);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, 1);
if
(!
empty
(
$data
)){
curl_setopt(
$ch
,CURLOPT_POST, 1);
curl_setopt(
$ch
, CURLOPT_POSTFIELDS,
$data
);
}
$outopt
= curl_exec(
$ch
);
curl_close(
$ch
);
$outopt
= json_decode(
$outopt
,true);
return
$outopt
;
}