由于 GDPR,阻止所有欧盟访客。

12

GDPR对于不知道违规行为的人施以巨额罚款,这是疯狂的。是否有一个简单且免费的PHP解决方案来处理我个人网站上的GDPR?我不需要跟踪用户,但我至少想知道谁访问了我的网站,例如,我想知道浏览器、操作系统、组织机构等信息。我当然可以阻止所有欧盟访客,但我知道很多人将他们的浏览器设置为英文,所以通过语言阻止是无效的。

作为一个非法律专业人士和仅维护一个没有任何收入的简单网站的人,我认识到我永远无法完全理解GDPR规定,也无法有资金保持更新。只有大型公司才能负担得起花费所需的时间、精力和金钱。因此,我需要一个简单的机制来阻止欧盟用户,否则我将采取一种保守的方法,即不收集任何访客数据。

这项GDPR法律威胁着那些不遵守规定的人经济死亡,但绝大多数人都不知道其模糊规则实际要求什么。这是一项偏向拥有资源的大公司的法律,并且是对小公司和个人的攻击。


2
个人网站受到影响。如果您拥有博客并记录IP地址,那现在是非法的。 - ndk
6
我真的认为你必须真正理解GDPR,而不是试图与之脱离联系。 - RiggsFolly
1
没有绝对可靠的方法。IP地址可以被欺骗,或者您可以使用VPN。浏览器上设置的语言可能不是来自欧洲的用户,即使他们使用欧洲语言。西班牙语是在许多国家都会使用的一种语言,而不仅仅是在西班牙。 - Qirel
6
没有一个团队的律师,谁也无法完全理解GDPR。 - ndk
1
@RiggsFolly 不完全是这样。它旨在保护欧盟国家的公民 - 这并不意味着决定遵守GDPR的美国公司需要将规则应用于非欧盟国家的公民。然而,几乎没有实际的方法可以通过“欧盟效忠度”来区分访问者,因此最终,如果您完全遵守法律(无论是否需要),将其应用于所有访问者/客户是更简单的选择。特别是如果我们谈论跨国公司 :) - Luaan
显示剩余3条评论
6个回答

10

首先,最好先阅读有关合法利益的信息--https://ico.org.uk/for-organisations/guide-to-the-general-data-protection-regulation-gdpr/legitimate-interests/when-can-we-rely-on-legitimate-interests/--然后询问您收集用户个人数据的法律依据是什么?

与您的问题相关联,实际上可以通过nginx和GeoIP数据库来实现。

安装nginx的GeoIP数据库:

apt-get install geoip-database-contrib -y

更新你的 nginx 配置(在 server {} 块之外):

# Block the EU continent from accessing the site

geoip_country /usr/share/GeoIP/GeoIP.dat;
geoip_city /usr/share/GeoIP/GeoLiteCity.dat;
map $geoip_city_continent_code $allow_visit {
   default 1;
   EU 0;
}

在您的server {}块中,禁用欧盟用户的日志记录并返回403:

# Disable logging for EU users
access_log /var/log/nginx/access.log combined if=$allow_visit;
# Block and return 403 error message to EU users
default_type text/plain;
if ($allow_visit = 0) {
        return 403 'You are prohibited from visiting this website due to GDPR compliance requirements.';
    }

重启nginx

service nginx restart

致谢 https://medium.com/@jacksonpalmer/gdpr-for-side-projects-blocking-all-eu-traffic-with-nginx-in-3-simple-steps-136ddd8078a4


2
原帖中提到他们有一个非常简单的网站,因此我会假设这是由虚拟共享服务器托管的。这意味着原帖作者将无法在自己的小站点上部署此网站,因为他无法以只读模式之外的方式访问服务器日志。 - Epiphany

1

对于那些不自信或无法访问和修改服务器配置的人,也有一个简单的插件可用,这对许多人来说可能更容易实现。您只需要根据网站提供的安装说明,在页面代码的开头标签中添加一个JavaScript标签即可。

https://www.ezigdpr.com/products/eu-visitor-blocker

通过在页面首次加载时触发阻止脚本,可以防止任何跟踪脚本、插件或像素加载。
如果您具备技术能力和访问权限,还可以考虑在服务器级别关闭IP日志记录;尽管有人认为,如果您不知道如何访问此内容,则可能不在GDPR的范围内。
您还可以阅读以下博客文章,其中概述了与阻止欧盟流量相关的不同考虑因素和合规陷阱。

https://www.ezigdpr.com/blog/2018/06/05/6/is-it-gdpr-compliant-to-block-eu-visitors


1
MaxMind拥有几乎所有编程语言的检测国家的API。此外,还有适用于Apache、Varnish和Nginx的模块。如果您想更详细地检测正确的城市,则需要支付费用,否则全部免费。
请参见https://dev.maxmind.com/geoip/geoip2/downloadable/#MaxMind_APIs 由于这个问题是关于PHP的,您可以通过首先安装composer包来在PHP中阻止欧盟国家: php composer.phar require geoip2/geoip2:~2.0 然后像这样使用。
const EU_COUNTRY_CODES = [
   'AT', 'BE', 'BG', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT',
   'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB'
];

require_once 'vendor/autoload.php';
use GeoIp2\Database\Reader;

$reader = new Reader('/usr/local/share/GeoIP/GeoIP2-City.mmdb');

$ip = $_SERVER['REMOTE_ADDR'];
// If you're behind a reverse proxy, you may need to do
// $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
// or whatever IP address header your proxy sets when forwarding the request

$record = $reader->country($ip);

if (in_array($record->country->isoCode, EU_COUNTRY_CODES), true){
    echo "We detected you where connecting from ";
    echo $record->country->name;
    echo ". We do not currently allow connections from the EU";
    die();
}

0

尽管欧盟GDPR存在,但请记住法院的法律管辖权将是您网站自己的“使用条款”协议中所述(或者应该是这种情况)。在法律上重要的是,网站所有者已经做出了“善意努力”,禁止那些成员国的网站。

鉴于此,以下是一个可重复使用的PHP函数,它使用“ip-api.com”API返回IP的位置数据并检查其是否与当前欧盟成员国的白名单匹配。白名单易于维护,这很好,因为进入和离开欧盟的国家处于不断变化之中。白名单是在2018年7月24日根据欧盟官方网站和维基百科的数据交叉核对而编制的。“ip-api.com”API可供个人免费使用(商业用途请联系),也可以从本地服务器运行,无需注册或域名要求。

function inEU($ip_input){

  // Validate the IP address
  if (filter_var($ip_input, FILTER_VALIDATE_IP) === false){
    // Not a valid IP address - build error response
    $message_string =
      '<div style="width:100%; margin-top:50px; text-align:center;">'.
        '<div style="width:100%; font-family:arial,sans-serif; font-size:24px; color:#c00; centered">'.
          'ERROR:&nbsp;<span style="color:#fd0">Invalid IP Address</span>'.
        '</div>'.
      '</div>';
    echo $message_string;
    exit;
  }

  // Array of country names and country codes of European Union member countries
  $eu_members = array(
    'Austria','AT',   'Belgium','BE',      'Bulgaria','BG',
    'Croatia','HR',   'Cyprus','CY',       'Czech Republic','CZ',
    'Denmark','DK',   'Estonia','EE',      'Finland','FI',
    'France','FR',    'Germany','DE',      'Greece','GR',
    'Hungary','HU',   'Ireland','IE',      'Italy','IT',
    'Latvia','LV',    'Lithuania','LT',    'Luxembourg','LU',
    'Malta','MT',     'Netherlands','NL',  'Netherlands Antilles','AN',
    'Poland','PL',    'Portugal','PT',     'Romania','RO',
    'Slovakia','SK',  'Slovenia','SI',     'Spain','ES',
    'Sweden','SE',    'United Kingdom','GB','UK'
  );
  $query_url = 'http://ip-api.com/json/'.$ip_input;  // Build query URL for IP to JSON Data request
  $ip_data_fetched = file_get_contents($query_url);  // Return IP Data JSON as a string
  $ip_data_fetched = utf8_encode($ip_data_fetched);  // Encode returned JSON string to utf-8 if needed
  $ip_data         = json_decode($ip_data_fetched);  // Decode utf-8 JSON string as PHP object

  // Get the Country and Country Code for the IP from the returned data
  $country     = $ip_data->country;      // Country Name (i.e; 'United States')
  $countryCode = $ip_data->countryCode;  // Country Code (i.e; 'US')

  // Check the EU members array for match to either country or country code
  $in_EU = false;                        // Ref for function boolean value returned - set false
  $num_members = count($eu_members);     // Number of indexes in EU members array (not # of members)
  for ($i = 0; $i < $num_members; $i++){
    $lc_eu_members = strtolower($eu_members[$i]);
    if ($lc_eu_members === strtolower($country) || $lc_eu_members === strtolower($countryCode)){
      $in_EU = true;
      break;
    }
  }
  return $in_EU;
}

而要使用该函数...

if (inEU( $ip )){
  // IP address IS in an EU country
}
else {
  // IP address IS NOT in an EU country
}

该函数还在同一循环中交叉检查返回的位置数据,因此如果一个变量中有错别字,它仍然可以使用另一个变量找到位置。两个变量都错误的可能性不大。
该函数可以轻松地适应许多其他返回JSON响应的IP到位置API。它也可以很容易地被调整为“允许白名单”,而不是“禁止白名单”。
希望这可以帮助到您!

0

我使用 websiteip2location.com,这是一个声称列出所有IP地址的网站。IP拒绝管理器是大多数使用C-Panel的托管服务提供的实用程序。

虽然这可能看起来很繁琐,但我打算复制欧盟每个国家的每个IP地址范围,并将其粘贴到C-Panel的IP拒绝管理器工具中。

我不确定这是否是最佳的技术解决方案,但这是我能想到的最好的方案。


1
有人知道这些IP地址的国家范围会多久更改一次吗?它们不可能永远保持不变。 - hostingutilities.com
@hostingutilities.com 大多数都是相对静态的,但它们随时可能发生变化。在过去的两个月里,我注意到了几个,并且我只关注那些正在积极攻击我维护的网站的攻击者。话虽如此...它并不可靠。最近,我不得不为德克萨斯州Datacamp托管的“荷兰”地址创建例外情况(该地址又托管了一个合法的VPN)。(尽管上面列出的网站已经消失了,但底层表格是一样的。) - Merennulli

0

您可以使用IP2Location PHP模块与免费的IP2Location LITE DB1数据库。

https://lite.ip2location.com/database/ip-country下载BIN数据库文件并提取BIN文件。

安装

将以下行添加到您的composer.json文件中。

{
  "require": {
    "ip2location/ip2location-php": "8.*"
  }
}

运行以下命令:

composer install

PHP 代码

require 'vendor/autoload.php'; 

$EEA_COUNTRIES = [
    'AT', 'BE', 'BG', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IS',
    'IT', 'LI', 'LV', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE'
];

$db = new \IP2Location\Database('./database/IP2LOCATION-LITE-DB1.BIN', \IP2Location\Database::FILE_IO);

$ip = $_SERVER['REMOTE_ADDR'];

$records = $db->lookup($ip, \IP2Location\Database::ALL);

if (in_array($records['countryCode'], $EEA_COUNTRIES)) {
    die('You are coming from ' . $records['countryName'] . ' which is part of the European Economic Area.<br />Visitors from the EU/EEA are not allowed access to this website due to GDPR.');
}

“NO”缺失。我们不在欧盟,但已经适应了这个疯狂的GDPR指令。 - G.Vanem
已添加了三个非欧盟国家作为欧洲经济区的一部分。 - Vlam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接