0
A
回答
0
IP到位置並不總是準確的,很容易被克服,但this might help you
0
PHP擁有的MaxMind的GeoIP的服務的原生支持。有關詳細信息,請參見this PECL extension。
+0
感謝我使用iplocation.net的唯一原因是,它從其他幾個服務獲取詳細信息,例如來自IP2Location(產品:DB4)的地理位置數據,地理位置數據IP地址(產品:最大),來自IP地址實驗室(Product:Pro)的地理定位數據以及來自GeoIP Javascript的來自MaxMind的地理定位數據,所以我想只需發佈並從本網站獲取,因爲我可以將所有這些細節解析爲數據庫, – user2521779
0
檢查這個網站了:http://ipinfodb.com/ip_location_api.php
他們提供API傳遞一個IP地址,還有服務回報地理位置回以XML/JSON,然後可以在你的PHP腳本解析。
如何使用它看起來像這樣的例子:
<?php
include('ip2locationlite.class.php');
//Load the class
$ipLite = new ip2location_lite;
$ipLite->setKey('<your_api_key>');
//Get errors and locations
$locations = $ipLite->getCity($_SERVER['REMOTE_ADDR']);
$errors = $ipLite->getError();
//Getting the result
echo "<p>\n";
echo "<strong>First result</strong><br />\n";
if (!empty($locations) && is_array($locations)) {
foreach ($locations as $field => $val) {
echo $field . ' : ' . $val . "<br />\n";
}
}
echo "</p>\n";
//Show errors
echo "<p>\n";
echo "<strong>Dump of all errors</strong><br />\n";
if (!empty($errors) && is_array($errors)) {
foreach ($errors as $error) {
echo var_dump($error) . "<br /><br />\n";
}
} else {
echo "No errors" . "<br />\n";
}
echo "</p>\n";
?>
也許這將讓你在正確的方向前進?
0
如果你真的想從http://www.iplocation.net/提取數據,然後在這裏是一個快速骯髒function
。但要使用此功能,您需要下載和包括PHP Simple HTML DOM Parser
這裏是你知道的ip代碼
<?php
require_once("path to simplehtmldom.php");
$ip_info = ip_info("223.196.190.40", 1);
print_r($ip_info);
/**
* It will output...
Array
(
[IP Address] => 223.196.190.40
[Country] => India
[Region] => Maharashtra
[City] => Pune
[ISP] => Idea Isp Subscriber Ip Pool
)
**/
/**
* ip_info()
* @param $ip - IP address you want to fetch data from
* @param $provider IP provider (1 = IP2Location, 2 = IPligence, 3 = IP Address Labs, 4 = MaxMind)
* @return array
*/
function ip_info($ip = "127.0.0.1", $provider = 1) {
$indx = array(
1 => 10,
2 => 11,
3 => 12,
4 => 13
);
$data = array();
$url = "http://www.iplocation.net/index.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, false);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "query=".urlencode($ip)."&submit=Query");
$response = curl_exec($ch);
$html = str_get_html($response);
if ($table = $html->find("table", $indx[$provider])) {
if ($tr1 = $table->find("tr", 1)) {
if ($headers = $tr1->find("td")) {
foreach($headers as $header) {
$data[trim($header->innertext)] = null;
}
}
}
if ($tr2 = $table->find("tr", 3)) {
reset($data);
if ($values = $tr2->find("td")) {
foreach($values as $value) {
$data[key($data)] = trim($value->plaintext);
next($data);
}
}
}
}
unset($html, $table, $tr1, $tr2, $headers, $values);
return $data;
}
?>
相關問題
- 1. asp.net網頁請求發佈參數
- 2. 如何接收網頁上的發佈請求?
- 3. 在網絡3.0中的發佈請求?
- 4. 如何僅允許來自我的網頁的發佈請求?
- 5. 用Perl中的請求標題發佈到網頁
- 6. 接收網:: ERR_EMPTY_RESPONSE與Nodejs發佈請求
- 7. 頁面刷新與發佈請求
- 8. iOS上的Android發佈請求
- 9. React Js Axios發佈請求不從網頁api返回機構
- 10. 將網頁請求發佈到xml文件
- 11. AFHTTPSessionManager發佈請求
- 12. JAVA:http發佈請求
- 13. PHP發佈請求
- 14. Python發佈請求
- 15. 發佈請求WebAPI2
- 16. REST發佈請求
- 17. 「無法找到請求的URL」當IIS上發佈網站
- 18. 請求網頁上的系統信息
- 19. 從iOS上的網頁請求BLOB
- 20. NodeJS:發佈請求和socket.io的組合
- 21. Node.js和https發佈請求的故事
- 22. 使用Python發送請求到網頁
- 23. HTTPS請求不發佈REST請求
- 24. REST API發佈請求 - 請求錯誤
- 25. Mootools的發佈請求
- 26. Unity中的發佈請求
- 27. Node.js的請求的網頁
- 28. 通過發佈請求上傳文件
- 29. 用wxHTTP上傳wxImage發佈請求
- 30. 在Windows XP上Vb6 http發佈請求
凌!=用戶 – 2013-06-25 21:44:16
你認爲這是一個明智的想法?因爲用戶至少有可能使用動態IP地址。然後,這將使所有這些信息無用。地理數據來自http://www.ipligence.com/ –