Download · Docs
News · Links · Awards

Cookie-lib.pl

  What is cookie-lib.pl?
    Cookie-lib.pl is a perl library, written in the spirit of cgi-lib.pl to help developers use cookies easily and effectively in web applications.
Why should I use it?
    If you have ever thought about using cookies in any of your scripts, this library makes it easy to set, delete and read cookies.
Why cookies are okay, in some cases.
    It is impossible to say "this technology is bad" because technology itself is neither good nor bad. It is simply technology. Rather, think about what you are going to do with cookies. Is what you are doing going to impose on an individual's privacy? Did you disclose what you are going to do with the information you collect? Cookies are cookies, and there are definitely good and valuable uses for them.
Download There is one version currently available.
Version 0.913 Released 11/20/1998.
News

11/20/1998 -
Ryan Aylward wrote in with a bug I had overlooked in the set_cookie routine. This fix (v0.913) should clear up alot of the problems people have been having setting cookies with non-Netscape browsers (and possibly Netscape browsers as well.

8/24/1998 -
Brennan Stehling wrote in with another bug. This one in the set_cookie routine. It involved the secure flag and the seconds being the same thing. A new library has been posted.

8/10/1998 -
Malcolm Parsons just informed me that there are 2 bugs in cookie-lib.pl, one having to do with the date of 12/31/99, and the other is that delete_cookie doesn't delete cookies with paths other than "/". I'll look into this.

Documentation Version 0.911 contains 4 functions to help you manipulate cookies.

get_cookie

    get_cookie reads the cookies set to the script by the browser. All cookie information is available though the environmental variable HTTP_COOKIE.
    To read the cookies, simply call the subroutine "get_cookie" from anywhere in your script (after you require "cookie-lib.pl"). Cookies are stored in an associative array like so:

      $cookie{name} = value
set_cookie
    set_cookie steps through the cookie associative array and sets what ever name/value pairs it finds. This means, in order to set a cookie you have to do something like this:

      $cookie{'color'} = blue;
      &set_cookie($expiration,$domain,$path,$secure);

    The arguments are as follows:
      $expiration
      Expiration date of the cookie, expressed in unix time format (seconds since Jan 1, 1970). All expiration dates are in Greenwich Mean Time. (Keep this in mind.)
      If you don't want to set any expiration, then use $expiration = "-1".
      If you want a "permanent" cookie (it lasts until 12/31/1998) then set $expiration = ""

      $domain
      Domain that the cookie data can be sent back to. Ordinarily you would leave this blank or $domain = "". This allows only you to read the cookie.

      $path
      Any file contained within $path (and it's subdirectories) can retreive the data contained within the cookie. For all pages on your server use "/", however in case of a subdirectory "/subdirectory".

      $secure
      Secure can either be equal to 0 or 1. If it's not a secure cookie, you can either leave it out, or $secure = 0. If for some reason you want to use secure cookies, set $secure = 1.

    Set_cookie must be called before you print "Content-type: text/html\n\n";
delete_cookie
    delete_cookie deletes a cookie from a users browser. In order to delete a cookie simply call the subroutine with the names of the cookies you want to delete. Eg.

      @cookies_to_delete = ("name","email","color");
      &delete_cookie(@cookies_to_delete);

    Delete_cookie must be called before you print "Content-type: text/html\n\n";
split_cookie
    split_cookie splits multi value cookies into it's constituent values. Eg.

      @values = &split_cookie($cookie{'favorite'}); #returns all the values.
      $value = &split_cookie($cookie{'favorite'}); #returns only the first value.

If you have any comments, questions, or modifications of the library, or you are successfully using the library, please contact me.

Links Netscape's cookie spec: http://home.netscape.com/newsref/std/cookie_spec.html.
Cgi-lib.pl homepage: http://cgi-lib.stanford.edu/.
General Cookie info: http://www.illuminatus.com/cookie.fcgi.
More general cookie info: http://www.cookiecentral.com/.
Like this? Check out my other software on my homepage.
Awards
Key Resource
Links2Go
Cookies

Last modified: Fri Nov 20 14:47:52 EST 1998