[英]Blocking a country IP using php
所以我有以下代碼:
$ip = getenv('HTTP_CLIENT_IP') ?: getenv('HTTP_X_FORWARDED_FOR') ?: getenv('HTTP_X_FORWARDED') ?: getenv('HTTP_FORWARDED_FOR') ?: getenv('HTTP_FORWARDED') ?: getenv('REMOTE_ADDR');
$details = json_decode(file_get_contents("http://ipinfo.io/$ip/json"));
if ($details->country == US):
{
echo "We are sorry, We cannot allow users from United States";
die();
}
elseif ($details->country == GB):
{
echo "We are sorry, We cannot allow users from United Kingdom";
die();
{
else:
show index script
問題是,某些美國和英國用戶仍可以看到該索引
看起來您正在與名為US或GB的常量進行比較。 您可能要檢查字符串。
$details->country === 'US'
。
問題出在http://ipinfo.io/ $ ip / json,我收到速率限制超出錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.