O'Reilly logo

Practical Internet Groupware by Jon Udell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting a Cookie

Here’s a generic Perl fragment that sets a cookie:

print "Content-type: text/html\n";
print "Set-Cookie:
            ProductAnalysisSubscriber=Aladdin%00926515678%00192.168.1;
            path=/cgi-bin; expires=Wed, 11-May-2000 00:00:00 GMT\n\n";

Or to continue with ASP-based PerlScript as in Example 12.4:

$Response->AddHeader("Set-Cookie", 
      ProductAnalysisSubscriber=Aladdin%00926515678%00192.168.1;
      path=/cgi-bin; expires=Wed, 11-May-2000 00:00:00 GMT\n\n";

On a Windows machine, when user Jon is logged in and the web server is localhost, Internet Explorer records that information in the file c:\WINNT\Profiles\Jon\Cookies\jon@localhost.txt.

On the same Windows machine, Communicator adds the following line to c:\program files\Netscape\users\jon\cookies.txt:

localhost   FALSE   /   cgi-bin   FALSE   958035600   ProductAnalysisSubscriber
     Aladdin%00926515678%00192.168.1

Table 12.1 lists the elements of this cookie.

Table 12-1. Anatomy of a Cookie

Element

Description

localhost

Which domain or specific server created and can read back the cookie? Use DOMAIN=.DomainName.com if multiple servers in a domain need to read the cookie.

FALSE

Can all machines in the server’s domain read the cookie? Defaults to FALSE. Only a single server can read it. Note that regardless of this setting, no server outside the cookie’s domain of origin can read it.

/cgi-bin

For which set of URLs will the browser send the cookie? In this case, only for scripts run from /cgi-bin. Defaults to /.

FALSE

Will your browser send its ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required