Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTony McKeown
Courses Plus Student 14,300 PointsEU Cookie Law
Mainly one for the Europeans. I'm hoping to launch a Rails site in the near future and I'm looking for help with this.
Can anyone sum up the basics of it for me? I know it has changed since it was originally introduced but is it now just a case of needing to have a pop-up message informing users that your site uses cookies? And then what for?
The other question is - how do I implement this so that it will remember not to show the message if someone has previously dismissed it?
Perhaps something Treehouse could cover briefly in a workshop as I'm sure they have a decent amount of European customers.
2 Answers
dylanpardee
Courses Plus Student 8,740 PointsI'm unaware of the details of the cookie law but I may have a simple way to implement this. I'm going to use PHP as an example but you could use anything.
A user will agree to your cookie agreement and then a cookie will be set. The cookie name would be "cookie_agreement" and would hold a value of true.
1 . When a user loads any page, check for the cookie_agreement cookie.
if(isset($_COOKIE['cookie_agreement'])) {
// Cookie use has been Approved
} else {
// Display Cookie Agreement pop-up
}
2 . When a user Agrees to the Cookie Agreement you set a cookie. This cookie is set to 30 days.
setcookie("cookie_agreement", "true", time() + (86400 * 30), '/');
You should implement this cookie check on each page. And if it ever fails display the cookie pop up.
This should work as long as checking for a cookie is allowed under the Cookie Law. As far as I can tell it is.
Hope this helps and good luck with your future plans :)
Tony McKeown
Courses Plus Student 14,300 PointsThanks, I don't really have a clue at the moment about how to use cookies. It will be something I have to look into. The ones that I'm using at the moment are ones built into gems like devise.
dylanpardee
Courses Plus Student 8,740 PointsIt wouldn't be hard to implement. It could be added into whatever you choose to use. I would use a simple
include_once ('/php/cookie_check.php);
This would make it a modification you could call on each page in PHP before a page loads. This would be some vary basic PHP.
I could post a fully working demo, if that's something you need.