【问题标题】:I want to block certain IP ranges / Regions / Country from accessing some of my pages我想阻止某些 IP 范围/地区/国家访问我的某些页面
【发布时间】:2018-03-20 14:06:55
【问题描述】:

我不希望我的整个网站在某个国家/地区被阻止,而是希望阻止某些国家或 IP 访问站点上的某些页面。

如果有人能在正确的方向上推动我,那就太好了。

【问题讨论】:

  • @sallycj 你觉得你能帮忙吗?

标签: geolocation web blocking geoip ip-blocking


【解决方案1】:

您没有指定您使用的语言,但您可以使用本地 IP 访问国家/地区数据库或查询 API 并在其国家/地区代码与您的阻止列表匹配时拒绝访问者:

$country = file_get_contents("http://api.db-ip.com/v2/free/{$_SERVER['REMOTE_ADDR']}/countryCode");
if (in_array($country, [ "US", "CA" ])) {
    header("Status: 403 Forbidden");
    die();
}

【讨论】:

  • 我正在使用 WordPress。我只需要在某些页面上阻止这些 IP。
猜你喜欢
  • 2018-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-18
  • 2010-10-13
  • 2021-01-12
相关资源
最近更新 更多