JavaScript EditorFreeware JavaScript Editor     Perl Tutorials 



Main Page Previous Section Next Section

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

    Main Page Previous Section Next Section
    


    JavaScript EditorJavaScript Verifier     Perl Tutorials


    ©