http://qs321.pair.com?node_id=6381


in reply to Recommended modules for handling cookies?

OK, say my address is: http://sub.domain.com. When setting cookie, what do I use for a domain address? domain.com, .domain.com, sub.domain.com, or .sub.domain.com? And to get a cookie, I use the $ENV{HTTP-COOKIE} command/variable, right?
  • Comment on Re: Recommended modules for handling cookies?

Replies are listed 'Best First'.
RE: Re: Recommended modules for handling cookies?
by btrott (Parson) on Mar 29, 2000 at 02:49 UTC
    Just try using "sub.domain.com" as the domain. If that's what your domain always is (ie. you don't have other domains like "foo.domain.com" that you want to set the same cookie for), just use that.

    And it's "HTTP_COOKIE", not "HTTP-COOKIE". It's an underscore ("_").

    And, finally, you really should be using CGI::Cookie. From the docs:

    To set cookies:

    # Create new cookies and send them $cookie1 = new CGI::Cookie(-name=>'ID',-value=>123456); print header(-cookie=>[$cookie1]);
    To fetch cookies:
    %cookies = fetch CGI::Cookie; $id = $cookies{'ID'}->value;
    Read the documentation for more info, particularly on setting the domain (look at the code setantae posted).
RE: Re: Recommended modules for handling cookies?
by setantae (Scribe) on Mar 29, 2000 at 02:47 UTC
    I don't want to sound patronising here, but are you sure that's a subdomain and not a host?

    Let's assume it's a host, so your domain is really domain.com, so that's what you put in for the domain.
    To retrieve a cookie, leave out the -value part if you're using the above method.

    setantae@eidosnet.co.uk|setantae|www.setantae.uklinux.net

RE: Re: Recommended modules for handling cookies?
by plaid (Chaplain) on Mar 29, 2000 at 02:49 UTC
    Straight from the CGI::Cookie man page
    2. domain This is a partial or complete domain name for which the cookie is valid. The browser will return the cookie to any host that matches the partial domain name. For example, if you specify a domain name of ".capricorn.com", then Netscape will return the cookie to Web servers running on any of the machines "www.capricorn.com", "ftp.capricorn.com", "feckless.capricorn.com", etc. Domain names must contain at least two periods to prevent attempts to match on top level domains like ".edu". If no domain is specified, then the browser will only return the cookie to servers on the host the cookie originated from.