books
Free Books / Computers / Practical mod_perl /

previous page: A.4. Redirecting While Maintaining Environment Variables
  
page up: Practical mod_perl | by Stas Bekman and Eric Cholet
  
next page: A.6. Sending Multiple Cookies with the mod_perl API

A.5. Handling Cookies




Description

This section is from the "Practical mod_perl" book, by Stas Bekman and Eric Cholet. Also available from Amazon: Practical mod_perl

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:

  • prev: A.4. Redirecting While Maintaining Environment Variables
  • Table of Contents
  • next: A.6. Sending Multiple Cookies with the mod_perl API

Books by Stas Bekman:















TOP
previous page: A.4. Redirecting While Maintaining Environment Variables
  
page up: Practical mod_perl | by Stas Bekman and Eric Cholet
  
next page: A.6. Sending Multiple Cookies with the mod_perl API

Topics

  • Animals
  • Architecture
  • Arts
  • Business
  • Computers
  • Crafts
  • Fairy Tales
  • Finance
  • Flora and Plants
  • Cooking
  • Gardening
  • Health and Healing
  • History
  • Home Improvements
  • Languages
  • New Age
  • Novels
  • Real Estate
  • Reference
  • Religion
  • Science
  • Society
  • Sports
  • Travel
  • Outdoors


Search

My Books

Headaches Begone! A Systemic Approach To Healing Your Headaches
Don't Let Your Bike Seat Ruin Your Sex Life Book

Discover

  • Answers FAQ

[ Privacy Policy | Terms of Use | About Us | Search ]

© 2007-2021 StasoSphere.com