/** * 获取用户真实 ip */function getip(){ static $realip; if (isset($_server)){ if (isset($_server[http_x_forwarded_for])){ $realip = $_server[http_x_forwarded_for]; } else if (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); } else if (getenv(http_client_ip)) { $realip = getenv(http_client_ip); } else { $realip = getenv(remote_addr); } } return $realip;}/** * 获取 ip 地理位置 * 淘宝ip接口 * @return: array */function getcity($ip){ $url=http://ip.taobao.com/service/getipinfo.php?ip=.$ip; $ip=json_decode(file_get_contents($url)); if((string)$ip->code=='1'){ return false; } $data = (array)$ip->data; return $data; }