您好,我這邊有找到兩篇文章可以幫助到你!
1.如何正確的取得使用者 IP?
2.以PHP Script查詢 IP 地址對應之相關資訊(國家、城市、ISP、Domain Name等)
希望有幫助到您~!
兩個結合在一起的用法
<pre class="c" name="code"><?php
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$myip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$myip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$myip = $_SERVER['REMOTE_ADDR'];
}
$contry = file_get_contents('http://api.hostip.info/country.php?ip=' . $myip);
echo $contry;
包成函數長這樣
<pre class="c" name="code"><?php
function get_ip_country()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$myip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$myip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$myip = $_SERVER['REMOTE_ADDR'];
}
$contry = file_get_contents('http://api.hostip.info/country.php?ip=' . $myip);
return $contry;
}
抓取系統設定的語係呢?