You might wonder why I don't just use the file that works? The reason is the original file is part of a shopping cart that does different things than I need to do with the new file. Besides, if I copy the file that works to the new location and run it then it won't set the cookie! I have all the permissions set correctly and the script RUNS okay, it just won't set the cookie.
When I run the script from the Unix command line it sure looks like it's trying to set a cookie:
PROMPT>>
PROMPT>> perl cart.cgi
Set-Cookie: TinyWrists=12345; path=/; expires=Mon, 25-Apr-2005 22:00:36 GMT
Date: Sun, 25 Apr 2004 22:00:36 GMT
Content-Type: text/html; charset=ISO-8859-1
And here's the code I'm using. This is it, I stripped it down to almost nothing! This code works perfectly in the original file. All I changed was the "value", which is set dynamically in the original file. (Yeah, I tried copying in that dynamic code also, but when that didn't work either, I wanted to make my cookie-setting code as simple as possible.)
use CGI; $cookie = $cgi->cookie(-name=>'TinyWrists', print $cgi->header(-cookie=>$cookie);
#!/usr/bin/perl -w
$cgi = new CGI;
-value=>'12345',
-expires=>'+365d',
-path=>'/');
[/pre]
I've spent about eight hours on this problem so far. What the heck is going on?
Sorry I couldn't get all of the code snippets to show up in blue. I spent about half an hour on THAT....
Thanks for your help, -MBJ-
The cookie gets set properly if the script is at the top level of the domain (same place as index.html). But if it's two levels down, no cookie.
I know the problem can't be the "path" parameter because that's for reading cookies, not setting them. I have mine set to "/" anyway, which makes the cookies available to the whole website. And I'm not using the "domain" parameter anywhere.
I scoured Google with no luck. Why the heck will the cookie not set if the script that sets it isn't at the top level?
Thanks for your help, -MBJ-
My earlier statement about how it works if the file is at the top level wasn't entirely accurate. I thought moving the file to the top level was what fixed it, but actually what fixed it was running the CGI file directly, instead of including it as an SSI. So here's the summary:
METHOD 1: <index.html> calls <cart.cgi> via SSI, and <cart.cgi> tries to write the cookie --> WILL NOT SET COOKIE. No error, just that the cookie doesn't get set.
METHOD 2: Use just one file, <index.cgi>, which both sets the cookie and dynamically creates the whole page --> WORKS FINE.
Is this expected behavior? I sure would like to be able to write cookies by calling my CGI file via SSI.
Thanks, -MBJ-