Listing 1: cookie-test.pl, Program to Create a Cookie
#!/usr/bin/perl -w
use strict;
use diagnostics;
use CGI;
# Create an instance of CGI
my $query = new CGI;
# Create a new cookie with a name "counter" and
# the value "1".
my $cookie = $query->cookie(-name => "counter",
-value => 1);
# Send a header to the user, including a cookie
print $query->header(-type => "text/html",
-cookie => $cookie);
# Send some HTML as a placeholder
print $query->start_html(-title => "Cookie set");
print "<P>The counter cookie is set to 1.</P>\n";
print $query->end_html;
Copyright © 1994 - 2019 Linux Journal. All rights reserved.