programming-examples/perl/CGI/Program to read cookies from the client's computer.pl
2019-11-15 12:59:38 +01:00

33 lines
713 B
Perl

#!perl
use CGI qw( :standard );
print header, start_html( "Read cookies" );
print "<STRONG>The folowing data is saved in a cookie on your ";
print "computer.<STRONG><BR><BR>";
%cookies = readCookies();
print "<TABLE>";
foreach $cookieName ( "Name", "Height", "Color" )
{
print "<TR>";
print " <TD>$cookieName</TD>";
print " <TD>$cookies{ $cookieName }</TD>";
print "</TR>";
}
print "</TABLE>";
print end_html;
sub readCookies
{
@cookieArray = split( "; ", $ENV{ 'HTTP_COOKIE' } );
foreach ( @cookieArray )
{
( $cookieName, $cookieValue ) = split ( "=", $_ );
$cookieHash{ $cookieName } = $cookieValue;
}
return %cookieHash;
}