2014-03-30 7 views
0

로 리디렉션 페이지를 만들 수 있습니다하지만 난 사용자 지오을 감지 코드 페이지를 만들고 새 페이지어떻게 전문가가 아니라고 새 페이지

하지만 뭔가 같은 그 모습에 리디렉션하려고했던 내 트래픽을 모니터링하는 것을 시도하고있다 누락 나는이 Geo redirect user just once using php

를 사용하려고 무엇을

잘 모릅니다하지만이 GeoIP.php을 얻을 어디 찾을 수있다

사람은 제가 작동하기 위해 필요한 팁을 줄 수

감사 보아스

+0

GeoIP.php는 [MaxMind GeoIP] (http://dev.maxmind.com/geoip/)에서 생각합니다. – MamaWalter

답변

0

이 체크 아웃해야합니다 :

http://www.php.net/manual/en/function.geoip-continent-code-by-name.php 단순히 2 자리 국가 코드를 반환합니다

$country = geoip_continent_code_by_name ($_SERVER['REMOTE_ADDR']); 

$ 국가를 사용합니다. 다음은 사용할 수 있어야하는 것입니다.

<?php 

    //Get the country code of the user, using REMOTE_ADDR is the most reliable way to do this 
    $country = geoip_continent_code_by_name ($_SERVER['REMOTE_ADDR']); 

    //Create a switch case to deal with the country codes 
    switch((string)$country) { 
    case 'AU': 
     $url = "http://www.site.au"; 
     break; 
    case 'CA': 
     $url = "http://www.site.ca"; 
     break; 

    //default case means, if you didn't provide a case (country code in your example), do this (otherwise known as a "catch all") 
    default: 
     $url = "http://defaultsite.com"; 

     } //End switchcase 

    //This if statement says as long as $url is not empty (! means not), update header location (this is the php way of forwarding) 
    if (!empty($url)){ 
     header('Location: '.$url); 
    } //End if statement 

?> 

try, catch 블록을 제거한 것을 알 수 있습니다. 그러나 이는 사용자 환경 설정이지만 대부분의 사람들은 기본 케이스를 제공하는 이유 인 스위치 케이스를 사용하여 좋아하지 않습니다.

100 % 작동해야합니다.

+0

내 게시물에서 나는 전문가가 아니다. 나는 일을하는 데 도움이되는 코드가 필요하다. 나는 총 noob이다. – boazor

+0

나는 내 포스트를 업데이트했다. – user1890328

관련 문제