cpanel에 국가, 도시 이름을 표시하는 방법은 무엇입니까?

cpanel에 국가, 도시 이름을 표시하는 방법은 무엇입니까?

저는 Cpanel을 사용하고 있습니다. 로그인 페이지에 국가 이름과 도시 이름을 다음과 같이 표시하고 싶습니다. 예:

 Your IP address is :  xxx.xxx.xxx.xxx
 Your Country name is: USA 
 Your City name is:  Seattle

위 정보의 경우 다음 PHP 코드를 사용하여 IP 주소를 표시할 수 있습니다.

<?php echo $_SERVER['REMOTE_ADDR']; ?>

국가 이름, 도시 이름과 같은 기타 사용자 정보를 표시하는 방법은 무엇입니까?

어떻게 해야 하는지 차근차근 안내해주세요.

답변1

당신은 아마도위치정보 API.

ipinfo.io간단한 일반 텍스트 반환 인터페이스를 제공하지만 많은 지리적 위치 API와 마찬가지로 특정 제한을 초과하는 경우 유료 버전의 서비스가 필요합니다(예: ipinfo.io의 경우 하루에 1000개 이상의 요청 또는 SSL이 필요함).

JSON이 아닌 버전의 ipinfo.io를 예로 사용하면 PHP 코드는 다음과 같습니다.

<?php 

    // This turns on error display without messing with php.ini
    // Delete the following two lines in production

    ini_set('display_errors',1); 
    error_reporting(E_ALL);

    // We avoid using $_SERVER['REMOTE_ADDR'] directly with a custom variable
    $ip = $_SERVER['REMOTE_ADDR'];

    // Otherwise, using the $_SERVER['REMOTE_ADDR'] directly
    //$city = file_get_contents('http://ipinfo.io/'. $_SERVER['REMOTE_ADDR']. '/city');
 
    // Using our custom $ip variable

    $city = file_get_contents('http://ipinfo.io/'. $ip. '/city');
    $country = file_get_contents('http://ipinfo.io/'. $ip. '/country');

    //$region = file_get_contents('http://ipinfo.io/'. $ip. '/region');
    

    // An alternate formatting of City State, Country
    //echo $city.' '.$region.', ' .$country;

    // Print our variables. <br> is a standard HTML line break.
    echo 'Your IP address is:   '.$ip;
    echo '<br>';
    echo 'Your Country name is: '.$country;
    echo '<br>'; 
    echo 'Your City name is:    '.$city;
?>

//를 사용하면 모든 줄을 생략할 수 있습니다. 이는 단지 주석/예제일 뿐이기 때문입니다. 마찬가지로 오류 표시 줄(ini_set/error_reporting)은 디버깅 전용입니다. 연결에는 변수 앞과 뒤의 마침표가 필요합니다. URL은 다음과 연결됩니다.

 Ex. http://ipinfo.io/123.123.123.123/city

이 형식으로 일반 텍스트를 반환합니다. 확인해 보세요ipinfo.io 개발자 페이지무엇을 반환할 수 있는지에 대한 몇 가지 아이디어를 더 알아보세요. 위 코드는 다음을 반환합니다.

Ex.
    Your IP address is :  xxx.xxx.xxx.xxx
    Your Country name is: US
    Your City name is:  Las Vegas

또는 "미국"과 "미국"을 비교하고 싶다면 다음과 같은 것을 시도해 볼 수도 있습니다.지오바이트 시티 세부정보레거시 API. "미국"을 반환하려면:

<?php

    function getIP() {
      foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
         if (array_key_exists($key, $_SERVER) === true) {
           foreach (explode(',', $_SERVER[$key]) as $ip) {
             if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
                   return $ip;
                }
             } 
          }
       }
    }

    $tags=json_decode(file_get_contents('http://getcitydetails.geobytes.com/GetCityDetails?fqcn='. getIP()), true);

    // Prints all available members of the $tags array, in case we forget our options
    //print_r($tags);

    // $tags[geobytesipaddress]) creates a non-fatal error so we use '' quotes around the array elements.
    print_r('Your IP address is: ' .$tags['geobytesipaddress']);
    echo '<br>';
    print_r('Your Country name is: ' .$tags['geobytescountry']);
    echo '<br>'; 
    print_r('Your City name is:    ' .$tags['geobytescity']);

?>

이것은 Geobytes 페이지의 예제 코드를 약간 수정한 것입니다. 작성된 대로 첫 번째 코드 예제의 출력을 복제하지만 전체 국가 이름을 포함합니다.

Ex.
    Your IP address is :  xxx.xxx.xxx.xxx
    Your Country name is: United States
    Your City name is:  Las Vegas

참고로 Geobytes API는 ipinfo.io보다 몇 가지 더 많은 옵션을 지원하는 것으로 보이며많이더 높은 미지급 요청 비율(중요한 경우)

관련 정보