Program to read cookies from the client's computer : Cookie « CGI « Perl






Program to read cookies from the client's computer

    


#!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; 
}

   
    
    
    
  








Related examples in the same category

1.A Simple Cookie Example
2.A Simple Cookie Example Using the CGI Module
3.Retrieving Cookies
4.Setting Cookie Expiration Without Using the CGI Module
5.Setting Cookie Expiration Using the CGI Module
6.Sending Multiple Cookies Using CGI.pm
7.Retrieving Multiple Cookies
8.Create cookie
9.Cookies and Session Tracking
10.Session tracking in our CGI scripts
11.Read cookie value
12.Time Period Abbreviations for the CGI Module's Header and Cookie Functions