Hello,
How can i block EVERYTHING from other countries than my own so people from other countries can't open the website?
Thanks.
Hello,
How can i block EVERYTHING from other countries than my own so people from other countries can't open the website?
Thanks.
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
Or you can use a htaccess way, which would be more sustainable: http://stackoverflow.com/questions/7...-united-states
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
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
, ... was shown that you can add more countries.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(); } ?>
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?
Thanks for helping!<?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();
}
?>
If you go to ipinfo.io what shows up for "country": ?
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)