#! /usr/bin/perl ### store incoming cookies into %cookieHash ##################### %cookieHash = (); @nameValuePairs = split(/; /, $ENV{"HTTP_COOKIE"}); foreach $pair (@nameValuePairs) { ($name, $value) = split(/=/, $pair); $cookieHash{$name} = $value; } ################################################################# if (exists $cookieHash{"VISITS"}) { $numvisits=$cookieHash{"VISITS"}+1; $welcome=""; } else { $numvisits=1; $welcome="Welcome to our site. "; } print "Set-Cookie: VISITS=$numvisits; path=/\n"; print "Content-type: text/html\n\n"; print<<PAGE; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=ISO-8859-1"/> <title>Session Counter Page</title></head> <body> <p>$welcome</p> <p>This is visit number $numvisits this session.</p> </body> </html> PAGE