2013-11-25 2 views

답변

4

이가 당신에게 도움이 될 수 있습니다 국가를 얻으면 그에 따라 리디렉션 할 수 있습니다.

<?PHP 

    function visitor_country() 
    { 
    $client = @$_SERVER['HTTP_CLIENT_IP']; 
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; 
    $remote = $_SERVER['REMOTE_ADDR']; 
    $result = "Unknown"; 
    if(filter_var($client, FILTER_VALIDATE_IP)) 
    { 
     $ip = $client; 
    } 
    elseif(filter_var($forward, FILTER_VALIDATE_IP)) 
    { 
     $ip = $forward; 
    } 
    else 
    { 
     $ip = $remote; 
    } 

    $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip)); 

    if($ip_data && $ip_data->geoplugin_countryName != null) 
    { 
     $result = $ip_data->geoplugin_countryName; 
    } 

    return $result; 
} 

echo visitor_country(); // Output Coutry name [Ex: United States] 

?> 

또는 Javascript.

<html> 
<head> 
    <script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script> 
</head> 
<body> 
    <script language="Javascript"> 
document.write("Welcome to our visitors from "+geoplugin_city()+", "+geoplugin_countryName()); 
// window.location = "http://www.yoururl.com"; /* you can forward user to url using this line of code according to your conditions 
    </script> 
</body> 
</html> 
0
당신은 PECL의 geoip_country_by_name() 사용자의 IP 주소가 자신의 나라를 얻을 수 있습니다

:

<?php 


    if (!empty($_SERVER['HTTP_CLIENT_IP'])) { 
     $ip = $_SERVER['HTTP_CLIENT_IP']; 
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
     $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; 
    } else { 
     $ip = $_SERVER['REMOTE_ADDR']; 
    } 

    $country = geoip_country_name_by_name($ip); 
    if ($country) { 
     echo 'This host is located in: ' . $country; 
     //header("Location: " . $somelocation); 
    } 
    ?> 
관련 문제