Hi all, I'm trying to write some CGI code. Need to look and see if a cookie is set; if not, set it and redirect back to the URL. Here's the piece of test code I have. When I run it, it hangs forever, so I'm assuming it's stuck in a loop.
Can anyone tell me where I went wrong?
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
# New CGI object
my $q = new CGI;
my $test = $q->cookie("test");
if (defined $test) {
print $q->header;
print $q->start_html('Test stuff');
print "<BR><BR>\n";
print "I got cookie value: $test<BR>\n";
print $q->end_html;
} else {
my $cookie = $q->cookie(-name => 'test',
-value => 'test value');
print $q->redirect (-cookie => $cookie, -uri => $q->self_url());
}
Thanks!
$ echo '$0 & $0 &' > foo; chmod a+x foo; foo;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|