开发者

How to fetch HTTP headers in perl when using CGI

开发者 https://www.devze.com 2023-02-09 07:24 出处:网络
I\'m usin开发者_StackOverflow社区g Perl/CGI/Apache and want to fetch the X-Forwarded-For HTTP header. How do I do that?Except for a few headers that are handled specially, CGI stores the value of Head

I'm usin开发者_StackOverflow社区g Perl/CGI/Apache and want to fetch the X-Forwarded-For HTTP header. How do I do that?


Except for a few headers that are handled specially, CGI stores the value of Header-Name: in the environment variable HTTP_HEADER_NAME. So, X-Forwarded-For (if present in the request) should be found in $ENV{HTTP_X_FORWARDED_FOR}.


CGI has a method for accessing HTTP request header fields, called "http", so you can say:

my $q = CGI->new()
print $q->http('X-Forwarded-For');

This works regardless whether you're running as a CGI, in fastcgi, mod_perl, etc...

0

精彩评论

暂无评论...
验证码 换一张
取 消