Recipe 21.5 Interrogating Headers

21.5.1 Problem

You want to learn the value of a header sent by the client.

21.5.2 Solution

Use the $r->header_in method:

$value = $r->header_in("Header-name");

21.5.3 Discussion

For example, suppose you want to discover the client's preferred language (as sent in the Accept-Language header).

if ($r->header_in("Accept-Language") !~ /\ben-US\b/i) {   $r->print("No furriners!");   return OK; }

If you want to access more than one header, use the $r->headers_in method, which returns a list of key-value pairs of all clients' request headers, which are typically assigned to a hash:

%h = $r->headers_in; if ($h{"Accept-Language"} !~ /\ben-US\b/i) {   $r->print("No furriners!");   return OK; }

21.5.4 See Also

Writing Apache Modules with Perl and C; Recipe 3.4 in mod_perl Developer's Cookbook; the Apache.pm manpage



Perl Cookbook
Perl Cookbook, Second Edition
ISBN: 0596003137
EAN: 2147483647
Year: 2003
Pages: 501

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net