phpbar.de logo

Mailinglisten-Archive

[php] Cookie revisited

[php] Cookie revisited

Werner Stuerenburg ws_(at)_art-quarter.com
Fri, 23 Jul 1999 15:53:00 +0200


3 Funde aufgrund der Hinweise von Manuel:

Für Münz ist die Herkunft des Namens ungeklärt. 
http://webopedia.internet.com hingegen sagt:

     The name cookie derives from UNIX objects called magic
     cookies. These are tokens that are attached to a user or
     program and change depending on the areas entered by the
     user or program. Cookies are also sometimes called
     persistent cookies because they typically stay in the
     browser for long periods of time. 

Dieser hier setzt genau das Beispiel von Münz ein mit folgendem
Kommentar:

     A First Timer! Since this is your first time I'll give you a
     big fat cookie. Reload this page To watch the number grow. If
     I had a Nickel for each hit to this page I would have
     $34396.10 since 6/24/97; 8:22:00 PM


http://builder.cnet.com/Programming/Kahn/111997/toolcc.html

gibt Beispielfunktionen, die besser sind als die von Münz, und
meines Erachtens auch erschöpfend.

// Heinle's function for retrieving a cookie.
function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

// An adaptation of Dorcht's function for setting a cookie.
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

// An adaptation of Dorcht's function for deleting a cookie.
function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


-- 
Mit freundlichem Gruss
Werner Stuerenburg

____________________________________________________________
ISIS Verlag - Uhlandstr. 8 - D-32120 Hiddenhausen -  Germany
Tel. 0(049)5224-9974-07, Fax-09, <mailto:ws_(at)_art-quarter.com>
 <http://pferdezeitung.com>    -   <http://art-quarter.com>


php::bar PHP Wiki   -   Listenarchive