homepage Welcome to WebmasterWorld Guest from 54.197.110.151
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Apache perl request object
expat123

10+ Year Member



 
Msg#: 4223933 posted 4:02 pm on Oct 29, 2010 (gmt 0)


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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4223933 posted 7:04 pm on Oct 29, 2010 (gmt 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
$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

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



 
Msg#: 4223933 posted 1:07 am on Oct 30, 2010 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved