#!perl
# Fig. 26.25: readCookies.pl
# Program to read cookies from the client's computer

use CGI qw( :standard );

print header, start_html( "Read cookies" );
print "<FONT FACE = \"ARIAL,SANS-SERIF\" SIZE = 3>";
print "<STRONG>The folowing data is saved in a cookie on your ";
print "computer.<STRONG><BR><BR>";

%cookies = readCookies(); 

print "<TABLE BORDER = \"5\" CELLSPACING = \"0\" ";
print "CELLPADDING = \"10\">";

foreach $cookieName ( "Name", "Height", "Color" )
{
   print "<TR>";
   print "   <TD BGCOLOR=#AAAAFF>$cookieName</TD>";
   print "   <TD BGCOLOR=#AAAAAA>$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; 
}

########################################################################## 
# (C) Copyright 2001 by Deitel & Associates, Inc. and Prentice Hall.     #
# All Rights Reserved.                                                   #
#                                                                        #
# DISCLAIMER: The authors and publisher of this book have used their     #
# best efforts in preparing the book. These efforts include the          #
# development, research, and testing of the theories and programs        #
# to determine their effectiveness. The authors and publisher make       #
# no warranty of any kind, expressed or implied, with regard to these    #
# programs or to the documentation contained in these books. The authors #
# and publisher shall not be liable in any event for incidental or       #
# consequential damages in connection with, or arising out of, the       #
# furnishing, performance, or use of these programs.                     #
##########################################################################
