As you may or may not know, the EU is introducing some new legislation that comes into effect on the 25th of May 2011 that will force website owners to expressly ask permission of their users to store a cookie on your site.

Now this is a little troubling, since anyone that is using Google Analytics will be storing a cookie on your machine just to know how well their site is performing! Unfortunately, a simple act as tracking your user behavior via a free, awesome service like GA will probably fall afoul of the ‘absolutely necessary’ clause that comes as part of the directive.

So how do you, as a site owner or manager of a site go about making the site compatible with these new regulations? Well, put simply it’s a mess, as a site owner you will need to:

  1. Get permission form the user prior to storing any cookies
  2. Clearly explain to the user about how you use cookies

Now that will be quite difficult for most site owners as if you use a framework, third party plugin, tracking tool etc. You might not even be aware of how many different cookies are being stored on your users machine, or what they do for that matter.

But that’s a different matter that can most likely be covered by some boilerplate legalese on a page somewhere (and I am sure there are lawyers out there already drafting the documentation). What’s more important is how you can stop your carefully crafted site from using cookies without expending too much time and effort.

One solution would be to simply ask the user before any JavaScript is executed on your page that could put a cookie on the machine. To that end, I put together a little script that will:

  1. Stop the browser from loading the page
  2. Ask for permission
  3. Offer to redirect the user to a page where you explain how the site uses cookies
  4. Will redirect the user to a custom page if they say ‘no’ where you can tell them very politely to grow a pair
  5. Only asks once, so once they say yes it’s all good they will never be asked again

The source code for the script is available here – do with it what you will, there’s no warranty from me. I’ve also put the script on a site called – so you can just add a short code snippet to your site and the script will take care of the rest.