How to block this?

Results 1 to 13 of 13
  1. #1
    Sorcerer Supreme UartigZone is offline
    Member +Rank
    Dec 2013 Join Date
    LoserlandLocation
    441Posts

    ! How to block this?

    Hello,

    How can i block EVERYTHING from other countries than my own so people from other countries can't open the website?

    Thanks.


  2. #2
    Elite Member Pastie is offline
    Member +Rank
    May 2014 Join Date
    FranceLocation
    133Posts

    Re: How to block this?

    Hello there UartigZone.

    You can use the http://ipinfo.io API for this. The PHP code would look something like this:
    $allowed_countries = array("US", "GB", ...);
    $country = file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/country");
    if(!in_array($country, $allowed_countries)) {
    // Display an error message, or redirect to another website
    }See http://ipinfo.io/developers for more details.

    Thanks,
    Mr. Doodle

  3. #3
    www.Epic Hosts.co.uk Terrum is offline
    Grand MasterRank
    Jun 2008 Join Date
    EpicHosts,co.ukLocation
    1,322Posts

    Re: How to block this?

    Or you can use a htaccess way, which would be more sustainable: http://stackoverflow.com/questions/7...-united-states

  4. #4
    Sorcerer Supreme UartigZone is offline
    Member +Rank
    Dec 2013 Join Date
    LoserlandLocation
    441Posts

    Re: How to block this?

    Quote Originally Posted by Mr Doodle View Post
    Hello there UartigZone.

    You can use the http://ipinfo.io API for this. The PHP code would look something like this:
    $allowed_countries = array("US", "GB", ...);
    $country = file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/country");
    if(!in_array($country, $allowed_countries)) {
    // Display an error message, or redirect to another website
    }See http://ipinfo.io/developers for more details.

    Thanks,
    Mr. Doodle
    Thank you.
    When i try to connect with US, the page is only white?

    - - - Updated - - -

    The script should send you to one page on my website and ONLY that page is possible to see when you are in the blocked countries? =)

    Thanks for helping me!
    Mathias

  5. #5
    Elite Member Pastie is offline
    Member +Rank
    May 2014 Join Date
    FranceLocation
    133Posts

    Re: How to block this?

    Just add a header('Location: page.php'); to where it says: // Display an error message, or redirect to another website
    That should work...

    Thanks,
    Mr. Doodle

  6. #6
    Sorcerer Supreme UartigZone is offline
    Member +Rank
    Dec 2013 Join Date
    LoserlandLocation
    441Posts

    Re: How to block this?

    Quote Originally Posted by Mr Doodle View Post
    Just add a header('Location: page.php'); to where it says: // Display an error message, or redirect to another website
    That should work...

    Thanks,
    Mr. Doodle
    Have tryed... Thanks....

    My code is:
    <?php
    $allowed_countries = array("US", "GB", ...);
    $country = file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/country");
    if(!in_array($country, $allowed_countries)) {
    ('Location: 500.php');
    ?>

  7. #7
    Elite Member Pastie is offline
    Member +Rank
    May 2014 Join Date
    FranceLocation
    133Posts

    Re: How to block this?

    Or you can block countries with PHP and MySql. See this if the previous didn't work: http://www.webhostingtalk.com/showthread.php?t=327502

    Thanks,
    Mr. Doodle

  8. #8
    Check http://arcturus.pw The General is offline
    DeveloperRank
    Aug 2011 Join Date
    7,613Posts

    Re: How to block this?

    Quote Originally Posted by UartigZone View Post
    Have tryed... Thanks....

    My code is:
    Code:
    <?php
    $allowed_countries = array("US", "GB");
    $country = file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/country");
    if(!in_array($country, $allowed_countries)) {
    header('Location: 500.php');
    exit();
    }
    ?>
    , ... was shown that you can add more countries.
    It is header('Location: page.php');
    exit();

  9. #9
    Sorcerer Supreme UartigZone is offline
    Member +Rank
    Dec 2013 Join Date
    LoserlandLocation
    441Posts

    Re: How to block this?

    Quote Originally Posted by The General View Post
    Code:
    <?php
    $allowed_countries = array("US", "GB");
    $country = file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/country");
    if(!in_array($country, $allowed_countries)) {
    header('Location: 500.php');
    exit();
    }
    ?>
    , ... was shown that you can add more countries.
    It is header('Location: page.php');
    exit();
    Thanks! Now it works but when i add Denmark ( DK ), Norway ( NO ) and Sweden ( SWE / SE ) it send me to the /blocked.php page? And its when i use a IP from GB, NO, DK and SWE ?

    Is it a bug or?

    <?php$allowed_countries = array("DK", "GB", "NO","SE");
    $country = file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/country");
    if(!in_array($country, $allowed_countries)) {
    header('Location: /blocked.php');
    exit();
    }
    ?>
    Thanks for helping!

  10. #10
    Check http://arcturus.pw The General is offline
    DeveloperRank
    Aug 2011 Join Date
    7,613Posts

    Re: How to block this?

    If you go to ipinfo.io what shows up for "country": ?

  11. #11
    Sorcerer Supreme UartigZone is offline
    Member +Rank
    Dec 2013 Join Date
    LoserlandLocation
    441Posts

    Re: How to block this?

    Quote Originally Posted by The General View Post
    If you go to ipinfo.io what shows up for "country": ?
    When on VPN =
    Country: DE
    And when on the normally computer the country is DK

    What do you think the bug or error is?

  12. #12
    Check http://arcturus.pw The General is offline
    DeveloperRank
    Aug 2011 Join Date
    7,613Posts

    Re: How to block this?

    Are u using a proxy as the REMOTE_ADDR might be set to that.
    Last edited by The General; 19-11-14 at 05:18 AM. Reason: Typo x)

  13. #13
    Sorcerer Supreme UartigZone is offline
    Member +Rank
    Dec 2013 Join Date
    LoserlandLocation
    441Posts

    Re: How to block this?

    Quote Originally Posted by The General View Post
    Or u using a proxy as the REMOTE_ADDR might be set to that.
    So what can i do ?



Advertisement