ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > DC Member Programs and Projects

GDPR Blocking (PHP Edition)

(1/4) > >>

Tuxman:
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.


--- Code: PHP ---<?php/*  Copyright © 2018 tux. <[email protected]>  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.

mouser:
Tux, just wanted to say I appreciate you sharing your projects with us.  :up:

Tuxman:
That sounds like "P.S.: You're banned forever."  ;D

I thought this is a developer site where developers share their projects, so I do that. (Although this is more like an unrequested coding snack...)
Anyway, you're welcome.

mouser:
There is no ps, it was a genuine expression of thanks.

Like many aspects of life, sometimes it takes perseverance and stubbornness and just charting your own path and doing things without much feedback until the people who appreciate your work find you.

Tuxman:
Ah, the day on which I lose interest in writing code just to keep boredom off me will be a sad day for me.

Navigation

[0] Message Index

[#] Next page

Go to full version