Welcome to WebmasterWorld Guest from 54.146.240.181

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Apache perl request object

     

expat123

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

10+ Year Member




Hello,

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');
}

janharders

7:04 pm on Oct 29, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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
$r->connection->remote_addr->ip_get


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 ;)

phranque

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



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

Featured Threads

Hot Threads This Week

Hot Threads This Month