1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to select a single Country to access a Website and DENY all other Countries?

Discussion in 'White Hat SEO' started by newnerd, Oct 24, 2013.

  1. newnerd

    newnerd Newbie

    Joined:
    Jan 19, 2013
    Messages:
    45
    Likes Received:
    7
    How to select a single country to access a Website and DENY access from all other countries to completely block access from the rest of the world. ?
     
  2. LukesDad

    LukesDad Junior Member

    Joined:
    Oct 24, 2009
    Messages:
    135
    Likes Received:
    71
    Location:
    Düsseldorf
    Home Page:
    that PHP should give you the countrycode:


    if (isset($_SERVER['HTTP_CLIENT_IP'])) {$real_ip_adress=$_SERVER['HTTP_CLIENT_IP'];}
    else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {$real_ip_adress=$_SERVER['HTTP_X_FORWARDED_FOR'];}
    else {$real_ip_adress=$_SERVER['REMOTE_ADDR'];}
    $cip=$real_ip_adress;
    $iptolocation='http://api.hostip.info/country.php?ip='.$cip;
    $creatorlocation=file_get_contents($iptolocation);
     
  3. black101

    black101 Supreme Member

    Joined:
    Dec 2, 2010
    Messages:
    1,406
    Likes Received:
    1,567
    Location:
    Switzerland
  4. LikesTM

    LikesTM Newbie

    Joined:
    Oct 13, 2013
    Messages:
    43
    Likes Received:
    28
    Location:
    UK
    phpcode.PNG
    (Can't post URL's)

    Replace GB with the country code you want to accept.
     
  5. ragster

    ragster Newbie

    Joined:
    Nov 17, 2009
    Messages:
    39
    Likes Received:
    18
    Wont hurt to do it in Google Webmaster Tools as well...
     
  6. gavinb

    gavinb Junior Member

    Joined:
    Dec 2, 2012
    Messages:
    129
    Likes Received:
    28
    Occupation:
    AM
    Location:
    CA
    yup simple php code to deny all ip ranges from any country can do it or modify your .htaaccess if you can to allow one particular ip range.
     
  7. newnerd

    newnerd Newbie

    Joined:
    Jan 19, 2013
    Messages:
    45
    Likes Received:
    7
    Mine is Wordpress site. Suppose, I want to make visible one of my Sub domain (example: abc.mywordpresssite.com) for USA only and when users from other Countries tries to access that sub domain will be redirected to main domain (example: mywordpresssite.com). - Please help how to do? Where to put code etc?
     
  8. MadStacks

    MadStacks BANNED BANNED

    Joined:
    Oct 20, 2013
    Messages:
    1,494
    Likes Received:
    493
    If you are using WordPress there are plug ins that allow you to block certain IP Addresses from both local, regional
    and nationwide ranges.