"This website uses cookies. By..." (Cookie Notification popup)

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 1937 Views - Last Post: 20 February 2014 - 10:45 AM

#16 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 897
  • Joined: 06-July 13

Re: "This website uses cookies. By..." (Cookie Notification popup)

Posted 08 February 2014 - 05:43 AM

I have also spotted another problem; It will work perfectly, but I must do this on every document that I put it on rather than one per all documents.
Was This Post Helpful? 0
  • +
  • -

#17 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 447
  • View blog
  • Posts: 1,931
  • Joined: 30-April 10

Re: "This website uses cookies. By..." (Cookie Notification popup)

Posted 08 February 2014 - 12:52 PM

A cookie is a small file containing a "key" or name and a "value".

For example:
Key : "loginName"
Value: "laytonsdad"

cookies.set("loginName","laytonsdad");
// sets loginName to "laytonsdad"
cookies.get("loginName");
gets loginName cookie value of "laytonsdad"

Was This Post Helpful? 0
  • +
  • -

#18 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 1,816
  • Joined: 15-January 14

Re: "This website uses cookies. By..." (Cookie Notification popup)

Posted 10 February 2014 - 09:28 AM

Right, a cookie is like a variable except the browser manages it. The browser could store it in files or a database or whatever, but the server tells the browser to create and save a cookie, and the browser sends the cookies back to the server when it makes a request. The basics of the cookie are like the above, a name and value (like a variable). Cookies can have other properties, like an expiration date for when the browser should delete it or stop sending it to the server, a path if the cookie should only be sent for certain pages on the server, an option for whether the cookie should only be sent over HTTPS, an option for whether the cookie should be accessible in Javascript, etc. There are several options for cookies, but at a basic level they are just names and values. Cookies are how PHP knows which session you're using, because your session ID is inside a cookie that your browser sends to the server to tell the server which session to use for you. If you understand that then things like PHP's setcookie function, or the methods in Javascript to set a cookie (or read a cookie), should make more sense. If you come across something like cookies that you're trying to use but you don't understand them, you need to research what they are before you try to use them. If you don't know whether or not you understand them, try explaining them to someone else. Use the rubber ducky method, get a rubber duck and tell it everything you know about cookies. If you sound like you don't know what you're talking about, then do some research. Rubber ducks also make effective debugging tools, if you explain to the duck how your code works then 9 times out of 10 you'll find the problem yourself.

This post has been edited by ArtificialSoldier: 10 February 2014 - 09:30 AM

Was This Post Helpful? 0
  • +
  • -

#19 chris98  Icon User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 897
  • Joined: 06-July 13

Re: "This website uses cookies. By..." (Cookie Notification popup)

Posted 20 February 2014 - 10:45 AM

I've finally done it - yippee!!! :)/>/>

Final Code: (without CSS, that still hasn't changed from above)
<?php if (!$_COOKIE['shn_cookie_policy']): ?>
<script type="text/javascript">
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";

}
</script>
<?php endif; ?>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<div id="notification">
Cookies help us deliver our services. By using our services, you agree to our use of cookies. <a href="http://www.mysite.com/privacy/cookies/" title="onclick="window.location(this.href)">Learn More</a>
<span class="dismiss"><a href="#" onclick="javascript:createCookie('shn_cookie_policy','notified',7)" title="Dismiss Notification">Dismiss Notification</a></span>
</div>
<?php 
if (!$_COOKIE['shn_cookie_policy']):
?>
<script>
   $( "#notification" ).fadeIn( 100, function() {

    $( "notification.dismiss" ).fadeIn( 100 );

  });

$( "span" ).click(function() {

  $( "#notification" ).fadeOut( 3000, function() {

    $( "notification.dismiss" ).fadeOut( 100 );

  });

  return false;

});
</script>
<?php endif; 


This post has been edited by chris98: 20 February 2014 - 10:53 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2