Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using cookies and Hashes

Cookies

Using cookies and Hashes

by  Haunter  Posted    (Edited  )
I will assume that people have some concept of flow control. Each line of code is excuted successively unless you break up the code with "subroutines" and "if" statements. Refer to faq452-653 for a more detailed look at this topic.

Now lets look at some code.

#Use the CGI module. Perl ships with this module now so #your server should have it
use CGI;
$q = new CGI;

##fill hash the has with some info

%info=( 'webpagename1'=> 'value',
"$webpagename2"=> "$value",
'webpagename3'=> 'value'
);

###Set the info in the cookie
##This step actually put the cookie in the proper format ##of HTTP headers and is required step.
$cookie= $q->cookie ( -name=>'cookiename',
-path=>'/',
-value=>\%info,
-domain=>..yourdomain.com',
-expires=>'365d');
###Set the cookie in the header
print $q->header(-cookie=>$cookie);

#Now you have to retreive the cookie

%visitdata = $query->cookie('cookiename');

##Now you can reference the data like this
##by the key you set

$dataIwant = $visitdata{'webpagename2'};

Hope this Helps
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top