topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • May 27, 2018, 02:56 PM
  • Proudly celebrating 13 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: GDPR Blocking (PHP Edition)  (Read 4612 times)

Tuxman

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,994
    • View Profile
    • Donate to Member
GDPR Blocking (PHP Edition)
« on: May 04, 2018, 05:27 AM »
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 [Select]
  1. <?php
  2. /*
  3.   Copyright © 2018 tux. <git@tuxproject.de>
  4.   This work is free. You can redistribute it and/or modify it under the
  5.   terms of the Do What The Fuck You Want To Public License, Version 2,
  6.   as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
  7.  
  8.   GDPR SHIELD [PHP draft v1]
  9.  
  10.   Prerequisites:
  11.   * PHP
  12.   * GeoIP as described here: http://php.net/manual/en/geoip.requirements.php
  13.  
  14.   Usage:
  15.   <?php require("gdprshield.php"); ?>
  16.   <!doctype html>
  17.   <html>
  18.     ...
  19.   </html>
  20. */
  21. $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"];
  22. $ip = $_SERVER["REMOTE_ADDR"];
  23. if (in_array(geoip_country_code_by_name($ip), $disallowed_countries)) {
  24.     die("Your country does not want you to be here.");
  25.  
  26.     /*
  27.       The above code displays a plain error text.
  28.       If you prefer to redirect to a full-featured HTML page,
  29.       you could delete it and use a Location header instead:
  30.     */
  31.     header("Location: GDPR_blocked.php", true, 451);
  32. }
  33. ?>

Enjoy. And feel free to extend/fix/implement it as you wish.
« Last Edit: May 04, 2018, 09:53 AM by Tuxman, Reason: enhanced redirection »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 38,547
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: GDPR Blocking (PHP Edition)
« Reply #1 on: May 04, 2018, 05:47 AM »
Tux, just wanted to say I appreciate you sharing your projects with us.  :up:

Tuxman

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,994
    • View Profile
    • Donate to Member
Re: GDPR Blocking (PHP Edition)
« Reply #2 on: May 04, 2018, 05:48 AM »
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

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 38,547
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: GDPR Blocking (PHP Edition)
« Reply #3 on: May 04, 2018, 06:09 AM »
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,994
    • View Profile
    • Donate to Member
Re: GDPR Blocking (PHP Edition)
« Reply #4 on: May 04, 2018, 06:15 AM »
Ah, the day on which I lose interest in writing code just to keep boredom off me will be a sad day for me.

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 9,439
    • View Profile
    • Donate to Member
Re: GDPR Blocking (PHP Edition)
« Reply #5 on: May 04, 2018, 09:41 AM »
I've actually been puzzling over the ramifications of this, so this seems like an alternative to the people that try to make money off of a bad mistake.

Thanks!

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 8,406
    • View Profile
    • The Blog of Deozaan
    • Donate to Member
Re: GDPR Blocking (PHP Edition)
« Reply #6 on: May 15, 2018, 12:34 PM »
Found a reference to this on Twitter:

https://twitter.com/...s/992370970928140288

Also, it seems to me that the GDPR Shield website is currently down. I wonder why... :-\

Tuxman

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,994
    • View Profile
    • Donate to Member
Re: GDPR Blocking (PHP Edition)
« Reply #7 on: May 15, 2018, 12:38 PM »
Too many customers?  ;D