# perl CGI which expects a cookie with name=XYZ123, if received
# then cookie's value is incremented by 1 and returned.
# this script can act as the final destination of the 302 Found redirect script above.
use strict;
use warnings;
use CGI;
use CGI::Cookie;
my $cgi = CGI->new;
my $cookies = fetch CGI::Cookie;
my $cookie = $cookies->{'COOKIE302'};
if( ! defined($cookie) ){
print $cgi->header() . "No cookie received.
";
exit(1)
}
my $cookie_value = $cookie->value;
if( ! ($cookie_value =~ /^([0-9]+)$/) ){
print $cgi->header() . "Invalid cookie received, value is '$cookie_value'.
";
exit(1)
}
$cookie->value($cookie_value+1);
print $cgi->header(
-charset => "utf-8",
-cookie => $cookie,
) . "this is 200 OK, you have been redirected OK, your cookie is valid, value was '".$cookie_value."' and now is '".$cookie->value."'.
";
exit(0);
1;
__END__