There is an expensive web service that makes your website GDPR-compliant by adding a JavaScript that redirects visitors from the EU to an error page.
This is my attempt to provide a simple and free PHP script for those who want to achieve the same result on server side.
Enjoy. And feel free to extend/fix/implement it as you wish.
This is my attempt to provide a simple and free PHP script for those who want to achieve the same result on server side.
Code: ( php)
<?php
/*
Copyright © 2018 tux. <git@tuxproject.de>
This work is free. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2,
as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
GDPR SHIELD [PHP draft v1]
Prerequisites:
* PHP
* GeoIP as described here: http://php.net/manual/en/geoip.requirements.php
Usage:
<?php require("gdprshield.php"); ?>
<!doctype html>
<html>
...
</html>
*/
$disallowed_countries = ["BE", "BG", "CZ", "DK", "DE", "EE", "IE", "EL", "ES", "FR", "HR", "IT", "CY", "LV", "LT", "LU", "HU", "MT", "NL", "AT", "PL", "PT", "RO", "SI", "SK", "FI", "SE", "UK"];
$ip = $_SERVER["REMOTE_ADDR"];
if (in_array(geoip_country_code_by_name($ip), $disallowed_countries)) {
die("Your country does not want you to be here.");
/*
The above code displays a plain error text.
If you prefer to redirect to a full-featured HTML page,
you could delete it and use a Location header instead:
*/
header("Location: GDPR_blocked.php", true, 451);
}
?>Enjoy. And feel free to extend/fix/implement it as you wish.















