您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP获取IP地址以及IP地址所在位置

2026/1/8 0:33:18发布11次查看
获取ip地址:
function getip(){ if (isset($_server)) { if (isset($_server['http_x_forwarded_for'])) { $realip = $_server['http_x_forwarded_for']; } elseif (isset($_server['http_client_ip'])) { $realip = $_server['http_client_ip']; } else { $realip = $_server['remote_addr']; } } else { if (getenv(http_x_forwarded_for)) { $realip = getenv( http_x_forwarded_for); } elseif (getenv(http_client_ip)) { $realip = getenv(http_client_ip); } else { $realip = getenv(remote_addr); } } return $realip;}echo $ip = getip();
//新浪接口根据ip查询所在区域信息
$res0 = file_get_contents(http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=$ip);$res0 = json_decode($res0,true);print_r($res0);echo
;
//淘宝接口根据ip查询所在区域信息
$res1 = file_get_contents(http://ip.taobao.com/service/getipinfo.php?ip=$ip);$res1 = json_decode($res1,true);print_r($res1);echo
;
以上就介绍了php获取ip地址以及ip地址所在位置,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product