Display content only to certain countries?

Discussion in 'PHP' started by ian_batten, Jan 31, 2010.

  1. #1
    Hi guys,

    Looking for some kind of method to display pieces of website content to users from specific countries only.

    I'd like to display a hover ad to users coming from the US when they login to their account.

    I looked at Maxmind GeoIP, but don't really get it..

    Any ideas would be greatly appreciated.
     
    ian_batten, Jan 31, 2010 IP
  2. krishmk

    krishmk Well-Known Member

    Messages:
    1,376
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    185
    #2
    You need to grab the visitors IP address: $_SERVER['REMOTE_ADDR']
    Validate this IP Address with a IP to country Database. They are some free ones available over the internet or some offer API for this.
    You can use an if/else statement to show/hide the content from the specific visitor.
     
    krishmk, Jan 31, 2010 IP
  3. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    astkboy2008, Jan 31, 2010 IP
  4. swtexans

    swtexans Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yeah.. i vote for IPGeolocation, they service is very awesome ;)
    i has used them for a few month, so far everything is ok
     
    swtexans, Jan 31, 2010 IP
  5. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    I do not think redirecting people according to their ip is a very good solution. try to find another solution. i live in UK and at work all our computers got IP addresses for Belgium. Everytime i try to watch something on bbc it is saying i am not allowed because i am not in UK.
     
    baris22, Feb 1, 2010 IP
  6. ian_batten

    ian_batten Well-Known Member

    Messages:
    1,991
    Likes Received:
    106
    Best Answers:
    0
    Trophy Points:
    185
    #6
    Baris, it's not "relocating", it's simply showing people country targetted offers. A few that are inaccurate won't be to much of a problem.

    Thanks for the input guys.
     
    ian_batten, Feb 5, 2010 IP
  7. Haney

    Haney Peon

    Messages:
    91
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I just posted this in another thread... There is a site you can go to to get a free script that can get you all sorts of info on an IP including country, country code, state/region... the site is http://geoplugin.com

    You can use this to do it...

    Get the plugin.class script, and...

    <?
    $ip=$_SERVER['REMOTE_ADDR'];
    require_once('geoplugin.class.php');
    
    // check country
    
    $geoplugin = new geoPlugin();
    $geoplugin->locate($ip);
    
    $hitfrom=$geoplugin->countryCode;
    
    if ($hitfrom=="US"){
    //shows content to US...
    } else if ($hitfrom=="CA"){
    // shows content to Canada...
    }
    ?>
    PHP:
     
    Haney, Feb 5, 2010 IP