Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Apache perl request object

4:02 pm on Oct 29, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 28, 2003
votes: 1


I am trying to implement the following code to determine the IP address of my user.

However, it seems to require a request object (my guess) I am not sure how to obtain the request object in Apache. mod_perl is installed if that is necessary. My server admin has not been much help on this.

$ip = $req->header('Client-IP') || $req->header('Remote-Addr');
if ($req->header('X-Forwarded-For')) {
$proxy = $ip;
$ip = $req->header('X-Forwarded-For');
7:04 pm on Oct 29, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:May 31, 2008
votes: 0

your handler-routine gets the request object as the first argument, so
my $req = shift;
should get you the object.
however, Remote-Addr is not a header.
If you're using mod_perl2, try

I'm not sure if you need to load any modules, I usually load
use Apache2::Connection;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN);
use Apache2::ServerUtil ();
use Apache2::RequestUtil ();
use Apache2::Log;

when working with mod_perl2, because I'm too lazy to figure out which ones I'll need ;)
1:07 am on Oct 30, 2010 (gmt 0)


WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
votes: 126

you might be looking for HTTP::Request:
http://search.cpan.org/~gaas/libwww-perl-5.837/lib/HTTP/Request.pm [search.cpan.org]