<?PHPfunctionget_ip () {//determine if the server allows $_server 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{ //do not allow to use getenv to obtain 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; } functionGetIP () {$ip=get_ip (); if($ip= = ' 127.0.0.1 '){ $myIp= ' Myip '; } //Initialize $curl=Curl_init (); //set the crawled URLcurl_setopt ($curl, Curlopt_url, ' http://ip.taobao.com/service/getIpInfo.php?ip= '.$myIp); //set the header file information as the data stream outputcurl_setopt ($curl, Curlopt_header, 0); //The information obtained is returned in the form of a file stream, rather than as a direct output. curl_setopt ($curl, Curlopt_returntransfer, 1); //Execute CommandCurl_multi_getcontent ($curl ); $data= Curl_exec ($curl); //Close URL RequestCurl_close ($curl); //show the data obtained returnJson_decode ($data,true); } functionWeather$chengshi){ $url= ' http://wthrcdn.etouch.cn/weather_mini?city= '.UrlEncode($chengshi); $html=file_get_contents($url); $jsondata= Gzdecode ($html); $data=json_decode ($jsondata,true); $arr=Array(); $arr[' Chengshi ']=$data[' Data '] [' City ']; $dangtian=$data[' Data '] [' Forecast '] [0]; $arr[' Gaowen ']=Str_replace("High Temperature",NULL,$dangtian[' High ']); $arr[' Diwen ']=Str_replace("Low Temperature",NULL,$dangtian[' Low ']); $arr[' Tianqi ']=$dangtian[' Type ']; return $arr; } $area=GetIP (); if(isset($area[' Data '] [' City '])){ $city=$area[' Data '] [' City ']; $weather= Weather ($city); Print_r($weather); }
PHP interface get public IP and get weather interface information