Another way to do it, if you don't want to be getting your hands in the dough is to use cookie-lib.pl. It's concept is based on cgi-lib.pl and works very well when you want to do a "quick n dirty".
Check it out: http://cgi-lib.stanford.edu/cgi-lib
HTH!
| [reply] |
Print to STDOUT the HTTP "Set-Cookie" header. That's the do-it-yourself way to set a cookie. The cookie header format is as such:
Set-Cookie: $name=$value; date=$cur_date; expires=$expires_date; path=$path; domain=$domain
$name is the name you want for your cookie,
$value is the string to be stored in the cookie,
$cur_date is date/time as of when the cookie was set, (format below)
$expires_date is the date when the cookie will expire (same format as $cur_date)
$path is the path on your website where the cookie will be valid (ex. "/cgi-bin"),
$domain is the domain where your cookie will be valid (ex. "www.hoobajub.com" or ".hoobajub.com"),
The date format is the following: "Wed, 5 Jan 2000 13:49:23 -0500"
The catch with cookies is that they are not immediately available to your CGI programs once you set them. You'll have to redirect the browser once you've set the cookie. I.e. Customer fills out form and submits -> your program processes date, prints cookie header and redirect header -> browser goes to redirect page -> your cgi can now read the cookie.
The other way to do it is use CGI.pm. Import that and you'll have the cookie() function. Called with a single argument (the name of the cookie you want to read) it returns as a scalar the value of the cookie. Check out Lincoln Stein's book "Official Guide to Programming with CGI.pm" for a detailed explanation of that package, or just read the source and use perldoc.
HTH | [reply] |