Apache-GeoIP
view release on metacpan or search on metacpan
Apache2/Geo/IP.pm view on Meta::CPAN
return $gi->org_by_name($host);
}
sub region_by_addr {
my $self = shift;
my $ip = shift || find_addr($self, $xforwardedfor);
return $gi->region_by_addr($ip);
}
sub region_by_name {
my $self = shift;
my $host = shift || $self->get_remote_host(Apache2::Const::REMOTE_HOST);
return $gi->region_by_name($host);
}
sub gi {
return $gi;
}
1;
__END__
=head1 NAME
Apache2::Geo::IP - Look up country by IP address
=head1 SYNOPSIS
# in httpd.conf
# PerlModule Apache2::HelloIP
#<Location /ip>
# SetHandler perl-script
# PerlResponseHandler Apache2::HelloIP
# PerlSetVar GeoIPDBFile "/usr/local/share/GeoIP/GeoIP.dat"
# PerlSetVar GeoIPFlag Standard
# PerlSetVar GeoIPXForwardedFor 1
#</Location>
# file Apache2::HelloIP
use Apache2::Geo::IP;
use strict;
use Apache2::Const -compile => 'OK';
sub handler {
my $r = Apache2::Geo::IP->new(shift);
$r->content_type('text/plain');
my $country = uc($r->country_code_by_addr());
$r->print($country);
return Apache2::OK;
}
1;
=head1 DESCRIPTION
This module constitutes a mod_perl (version 2) interface to the
L<Geo::IP> module, which looks up in a database a country of origin of
an IP address. This database simply contains
IP blocks as keys, and countries as values. This database should be more
complete and accurate than reverse DNS lookups.
This module can be used to automatically select the geographically
closest mirror, to analyze your web server logs
to determine the countries of your visiters, for credit card fraud
detection, and for software export controls.
To find a country for an IP address, this module a finds the Network
that contains the IP address, then returns the country the Network is
assigned to.
=head1 CONFIGURATION
This module subclasses I<Apache2::RequestRec>, and can be used
as follows in an Apache module.
# file Apache2::HelloIP
use Apache2::Geo::IP;
use strict;
sub handler {
my $r = Apache2::Geo::IP->new(shift);
# continue along
}
The directives in F<httpd.conf> are as follows:
<Location /ip>
PerlSetVar GeoIPDBFile "/usr/local/share/GeoIP/GeoIP.dat"
PerlSetVar GeoIPFlag Standard
# other directives
</Location>
The C<PerlSetVar> directives available are
=over 4
=item PerlSetVar GeoIPDBFile "/path/to/GeoIP.dat"
This specifies the location of the F<GeoIP.dat> file.
If not given, it defaults to the location specified
upon installing the L<Geo::IP> module.
=item PerlSetVar GeoIPFlag Standard
Flags can be set to either I<STANDARD>, or for faster performance
(at a cost of using more memory), I<MEMORY_CACHE>. When using memory
cache you can force a reload if the file is updated by setting I<CHECK_CACHE>.
I<INDEX_CACHE> caches the most frequently accessed index portion of the database,
resulting in faster lookups than I<STANDARD>, but less memory usage than
I<MEMORY_CACHE> - this is useful for larger databases such as GeoIP
Organization and GeoIP City. Note, for GeoIP Country, Region and Netspeed databases,
I<INDEX_CACHE> is equivalent to I<MEMORY_CACHE>.
Multiple values of I<GeoIPFlag> can be set by specifying them
using I<PerlAddVar>. If no values are specified, I<STANDARD> is used.
( run in 0.511 second using v1.01-cache-2.11-cpan-39bf76dae61 )