 |
 |
What is wrong w/ my cgi code?
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status:
Offline
|
|
I want to put a cookie on my web page so i know when people have visited. Here is my page. The sentence at the bottom shows up so I know the page is running.
What is wrong w/ my cookie line?
#!/usr/bin/perl -w
print "Set-Cookie: Visited=1; path=/cgi-bin/; domain=.mydomain.com;\n";
print "Content-type:text/html\n\n";
print "<P>A visiting cookie has been sent to the users browser.</P>\n";
(Last edited by poulh; Apr 14, 2003 at 09:58 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status:
Offline
|
|
Is that the extent of your .cgi?
I can see two potential issues. One is the lack of HTTP headers.
All HTTP responses should begin with a header line, typically "HTTP/1.1 200 OK", which lets the client know the HTTP version of the response.
The other is the inclusion of the semicolon at the end of the Set-Cookie line. The HTTP spec does not allow for the semicolon, but some browsers handle it gracefully (i.e. ignore it), while others don't.
|
|
Gods don't kill people - people with Gods kill people.
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status:
Offline
|
|
I think it was not having an expiration date. I was looking in Camino's cookie file which only got written out on quitting. However by not having an epiration date the cookie expired at the end of the session so it would never get written out.
Adding the date worked and I took off the ending semi-colon.
However I did not need to add the HTTP/1.1 line.
Thanks for your help!
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
You do know that there are all sorts of libraries to do this stuff for you, right? You can do "setHeader()" instead of writing out headers yourself.
Writing CGIs like this is a good way to understand the underlying technology, but it's a terrible way to write production applications today.
Then again, any CGI is probably a bad idea today. Go with an application server like Zope/Plone/Tomcat/JBoss/WebLogic/etc
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status:
Offline
|
|
Yep... I know about the headers. I just wanted to see if I could do it "by hand" just so I know what those headers are really doing behind the scenes.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status:
Offline
|
|
Ugh, another problem...
My cookie appears (as in I get it back thru $ENV{"HTTP_COOKIE"} ).
It works in every Gecko-Browser, IE for Win/Mac, Omniweb,
But not Safari!!!! Is this something that isn't finished yet or does safari do it differently. Here is my complete code...
#!/usr/bin/perl -w
sub SetCookie
{
$cookieName = $_[0];
$cookieValue = $_[1];
$theTime = $_[2];
@array = gmtime($theTime);
$day = (qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday))[$array[6]];
$month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$array[4]];
$year = $array[5] + 1900;
$timeString = "$day, $array[3]-$month-$year $array[2]:$array[1]:$array[0]";
print "Set-Cookie: $cookieName=$cookieValue; path=/cgi-bin/; expires=$timeString; domain=.my_domain.com\n";
}
$theTime = time;
$theTime = $theTime + 1800; #30 minutes
SetCookie ("Value", 1, $theTime);
SetCookie ("ID", $ENV{"UNIQUE_ID"}, $theTime);
print "Content-type:text/html\n\n";
print "<P>The counter cookie is /cgi-bin/ set to 1.</P>\n";
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|