Posted By

shodan_uk on 02/20/11


Tagged

js


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dop3


Cookie


 / Published in: JavaScript
 

URL: http://wiki.lawtoncommsgroup.com/index.php?title=Cookies&printable=yes

Authour: Mike Rumble <@rumble>

  1. Cookie = (function(){
  2. return {
  3. set : function(name, value, expires, path, domain, secure) {
  4. var today = new Date();
  5. today.setTime( today.getTime() );
  6. if (expires) expires = expires * 1000 * 60 * 60 * 24;
  7. var expires_date = new Date( today.getTime() + (expires) );
  8. document.cookie = name + "=" + value +
  9. ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
  10. ((path) ? ";path=" + path : "") +
  11. ((domain) ? ";domain=" + domain : "") +
  12. ((secure) ? ";secure" : "");
  13. },
  14. get : function(name) {
  15. var start = document.cookie.indexOf( name + "=" );
  16. var len = start + name.length + 1;
  17. if((!start)&&(name != document.cookie.substring(0, name.length))){
  18. return null;
  19. }
  20. if(start == -1) return null;
  21. var end = document.cookie.indexOf( ";", len);
  22. if(end == -1) end = document.cookie.length;
  23. return document.cookie.substring(len, end);
  24. },
  25. destroy : function(name, path, domain) {
  26. if (getCookie(name)) document.cookie = name + "=" +
  27. ((path) ? ";path=" + path : "") +
  28. ((domain) ? ";domain=" + domain : "") +
  29. ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  30. }
  31. }
  32. }());

Report this snippet  

You need to login to post a comment.