I'm using Perl/CGI/Apache and want to fetch the X-Forwarded-For HTTP header. How do I do that?
Asked
Active
Viewed 9,297 times
2 Answers
16
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}
.

cjm
- 61,471
- 9
- 126
- 175
-
@cjm, thank you so much. Is there any rfc or protocol or standard defines, web server passes http header to cgi process in environment variables way with prefix HTTP_? – http8086 May 15 '18 at 12:13
-
@hylepo, [RFC 3875](https://tools.ietf.org/html/rfc3875#section-4.1.18) – cjm Jun 25 '18 at 19:58