I've learned just enough Perl to write the following program so I'm
probably making a basic mistake. The program is designed to be
called from a page by an image tag. It first checks for an existing
cookie. If there's a cookie it just returns the GIF. If there's no
cookie then it checks for the referer, sets the cookie and then
returns the GIF. The problem comes when checking for an existing
cookie. If I remove the conditional at 1 & 2 which checks for a
cookie, the program runs fine. It sets the cookie and returns the
image. If left in I get a "500" error.
#!/usr/bin/perl
# cset.cgi - set a cookie
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
# check for cookie, if no cookie then check for referer
# and set cookie
unless ($ENV{'HTTP_COOKIE'}) { # 1
if ($ENV{'HTTP_REFERER'} eq "") {
$referer = "None"
}
else {
$referer = $ENV{'HTTP_REFERER'}
}
$name = "Thanks";
$to_set = cookie(-name => $name,
-value => $referer,
-expires => "+30d",
);
print header(-cookie => $to_set);
} # 2
#print clear GIF
$image = "logo.gif";
print img {src=>$image};
<IMG SRC=$image>
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.