Created
May 25, 2018 12:50
-
-
Save gaptekupdate/67402695d09b371c1504cf42d0f97a2b to your computer and use it in GitHub Desktop.
Blocking Website Access from GDPR Countries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Blocking Website Access from GDPR Countries | |
Author: M.Februriyanto (fb.me/ebo78) | |
Version: 1.0.0 May 25, 2018 | |
Requires: Cloudflare IP Geolocation - HTTP_CF_IPCOUNTRY - ISO 3166-1 Alpha 2 format | |
GDPR Country List by: https://gist.github.com/henrik/1688572 | |
Function derivered from: https://etzelstorfer.com/en/check-country-eu-php/ | |
*/ | |
$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"]; | |
if (isGDPR($country_code) === TRUE) { | |
header( "HTTP/1.0 403 You are prohibited from visiting this website due to GDPR compliance requirements.", TRUE, 403); | |
die("We're sorry. Our website is currently unavailable in most European countries. | |
We recognise you are attempting to access this website from a country belonging to the European Economic Area (EEA) including the EU | |
which enforces the General Data Protection Regulation (GDPR) and therefore cannot grant you access at this time. | |
\n | |
(403 error.)"); | |
} | |
function isGDPR($countrycode){ | |
$gdpr_countrycodes = array( | |
'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', | |
'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB', | |
'GF', 'GP', 'MQ', 'ME', 'YT', 'RE', 'MF', 'GI', 'AX', 'PM', 'GL', 'BL', 'SX', 'AW', | |
'CW', 'WF', 'PF', 'NC', 'TF', 'AI', 'BM', 'IO', 'VG', 'KY', 'FK', 'MS', 'PN', 'SH', | |
'GS', 'TC', 'AD', 'LI', 'MC', 'SM', 'VA', 'JE', 'GG' | |
); | |
return(in_array($countrycode, $gdpr_countrycodes)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment