Since my main website runs an older version of Drupal my choices of a simple plug-in or module are limited. I wanted something that would give the required warning before any cookies are sent, give them the choice to stay or go, and only bother people visiting from countries in the EU. I didn’t find anything that I liked that was also compatible with my site so I had to go to plan-B.
I remembered that Cloudflare can block or ‘challenge’ by country. This ‘challenge’ displays a web-page and requires a CAPTCHA form to be filled out before continuing. Since this particular website already uses Cloudflrae I decided to see how difficult it would be to create custom rules and a custom challenge-page to make the dipshits in charge at the EU happy. Turns out, it was pretty simple.
First, I had to setup the Cloudflare Firewall Rules. This is pretty simple by just entering the two-letter country code for all 28 countries that comprise the EU. To get the specific country code for each country Google it or go here: Internet Country Codes
Entering the country code in your Cloudflare firewall is easy. Just type it in and select “challenge”:
After entering all the EU country codes, you can then customize your “Challenge Page”. This is the page that will be shown to visitors coming from the countries that you’ve set to “challenge”.
For your challenge page you will need to create a static HTML page that is hosted “outside” of your Drupal (or WordPress, Joomla, etc) installation. If you use your CMS to create the page a cookie would be served up when displaying it, violating the EU cookie law. Imagine the horror!! To make the CAPTCHA show, be sure to add the text “::CAPTCHA_BOX::” where you want the CAPTCHA form to be displayed.
Make sure your .HTML file is uploaded to your server and add it to Cloudflare by clicking the EDIT button and typing in the URL. You can then click PREVIEW to make sure it looks and works the way you envisioned. Mine looks like this:
That’s pretty much all it takes! The changes take effect immediately. Any time you want to update or change the wording of your new EU Cookie Consent page just edit the HTML file you uploaded to your server and Cloudflare will automatically display the updated text.