![]() |
Practical mod_perl / HTML Version / | ![]() |
||
![]() |
||||
![]() |
![]() |
|||
![]() |
![]() |
|||
![]() |
||||
|
|
||||
![]() |
![]() |
|||
![]() |
A.5. Handling Cookies |
![]() |
||
![]() |
||||
![]() |
![]() |
![]() |
||
![]() |
||||
Unless you use a module such as CGI::Cookie or Apache::Cookie, you need to handle cookies yourself. Cookies are accessed via the $ENV{HTTP_COOKIE} environment variable. You can print the raw cookie string as $ENV{HTTP_COOKIE}. Here is a fairly well-known bit of code to take cookie values and put them into a hash:
sub get_cookies {
# cookies are separated by a semicolon and a space, this will
# split them and return a hash of cookies
my @rawCookies = split /; /, $ENV{'HTTP_COOKIE'};
my %cookies;
foreach (@rawCookies){
my($key, $val) = split /=/, $_;
$cookies{$key} = $val;
}
return %cookies;
}
And here's a slimmer version:
sub get_cookies {
map { split /=/, $_, 2 } split /; /, $ENV{'HTTP_COOKIE'};
}
 
Continue to:
mod_perl, modperl, Apache, perl, cgi, html, mod_perl, e-commerce, scalability, free, open source, OSS, apache, squid, high availability, modperl, linux, unix, Web, www, mod_perl, webserver, admin, apache, book, webmaster, tools, modperl, guide, docs, documentation, help, mod_perl, perl, information, apache, script, errata, eric cholet, perl, apache, mod-perl, stas bekman, mod_perl, cool, perl, Apache, performance, speed, choice
![]() |
Other projects to check out: meta-religion.com is for those interested in Religious, Spiritual and Esoteric Phenomena. i-want-a-better.com is a community of people discussing what they would like to be improved in their lives and things they use and interact with. You may also want to find a healer in your area or read articles on variety of topics.