@H_502_0@获取IP有两种方法,复杂的被我注释掉了,如果你想使用复杂的,去掉注释,再把简单的注释掉就可以了。
@H_502_0@<div class="msgborder" id="PHPcode3"><?php// 复杂获取本地ip地址/ if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown')) { $SA_IP = getenv('HTTP_CLIENT_IP');} elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown')) { $SA_IP = getenv('HTTP_X_FORWARDED_FOR');} elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'),'unknown')) { $SA_IP = getenv('REMOTE_ADDR');} elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'],'unknown')) { $SA_IP = $_SERVER['REMOTE_ADDR'];} /$SA_IP=$_SERVER['REMOTE_ADDR'];//简单获取本地ip地址//定义一个函数根据ip获取城市名,使用新浪的天气预报function getIPLoc_sina($queryIP){ $url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=' . $queryIP; $ch = curl_init($url); curl_setopt($ch,CURLOPT_ENCODING,'utf8'); curl_setopt($ch,CURLOPT_TIMEOUT,10); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $location = curl_exec($ch); $location = json_decode($location); curl_close($ch); $loc = ""; if ($location === FALSE) return ""; if (empty($location->desc)) { $loc = $location->city; $full_loc = $location->province . $location->city . $location->district . $location->isp; } else { $loc = $location->desc; } return $loc;}$city = getIPLoc_sina("$SAIP");
@H502_0@$citycode = mb_convertencoding($city,"gb2312","utf-8");
@H502_0@$doc = new DOMDocument();if (<a href="mailto:!@$doc->load("http://php.weather.sina.com.cn/xml.php?city">!@$doc->load("http://php.weather.sina.com.cn/xml.php?city=" . $citycode . "&password=DJOYnieT8234jlsK&day=0")) { echo "Get data Failed!!\n"; return;}
@H_502_0@$city = $doc->getElementsByTagName("city")->item(0)->nodeValue;$stat1 = $doc->getElementsByTagName("status1")->item(0)->nodeValue;$chy_shuoming = $doc->getElementsByTagName("chy_shuoming")->item(0)->nodeValue;$tmp1 = $doc->getElementsByTagName("temperature1")->item(0)->nodeValue;$tmp2 = $doc->getElementsByTagName("temperature2")->item(0)->nodeValue;$date = $doc->getElementsByTagName("savedate_weather")->item(0)->nodeValue;$pollution_l = $doc->getElementsByTagName("pollution_l")->item(0)->nodeValue;$gm_s = $doc->getElementsByTagName("gms")->item(0)->nodeValue;
@H5020@echo '