NAME
Apache2::Geo::IP::Record - Contains city information for GeoIP City Edition
SYNOPSIS
# in httpd.conf
# PerlModule Apache2::HelloIP
#<Location /ip>
# SetHandler perl-script
# PerlResponseHandler Apache2::HelloIP
# PerlSetVar GeoIPDBCityFile "/usr/local/share/GeoIP/GeoIPCity.dat"
# PerlSetVar GeoIPFlag Standard
#</Location>
# file Apache2::HelloIP
use Apache2::Geo::IP::Record;
use strict;
use Apache2::Const -compile => 'OK';
sub handler {
my $r = Apache2::Geo::IP::Record->new(shift);
$r->content_type('text/plain');
my $city = $r->city;
$r->print($city);
return Apache2::Const::OK;
}
1;
DESCRIPTION
This module constitutes a mod_perl (version 2) interface to the Geo::IP module which contains location information returned by the GeoIP City database.
CONFIGURATION
This module subclasses Apache2::RequestReq, and can be used as follows in an Apache module.
# file Apache2::HelloIP
use Apache2::Geo::IP::Record;
use strict;
sub handler {
my $r = Apache2::Geo::IP::Record->new(shift);
# continue along
}
The directives in httpd.conf are as follows:
PerlModule Apache2::HelloIP
<Location /ip>
PerlSetVar GeoIPDBCityFile "/usr/local/share/GeoIP/GeoIPCity.dat"
PerlSetVar GeoIPFlag Standard
# other directives
</Location>
The PerlSetVar
directives available are
- PerlSetVar GeoIPDBCityFile "/path/to/GeoIPCity.dat"
-
This specifies the location of the GeoIPCity.dat file. If not given, it defaults to the location optionally specified upon installing the module.
- PerlSetVar GeoIPFlag Standard
-
This can be set to STANDARD, or for faster performance but at a cost of using more memory, MEMORY_CACHE. When using memory cache you can force a reload if the file is updated by using CHECK_CACHE. If not specified, STANDARD is used.
METHODS
The available methods are as follows.
- $code = $r->country_code( [$conn] );
-
Returns the ISO 3166 country code for an IP address or hostname. If $conn is not given, the value obtained by
$r->connection->remote_ip
is used. - $code = $r->country_code3( [$conn] );
-
Returns the 3 letter country code for an IP address or hostname. If $conn is not given, the value obtained by
$r->connection->remote_ip
is used. - $name = $r->country_name( [$conn] );
-
Returns the full country name for an IP address or hostname. If $conn is not given, the value obtained by
$r->connection->remote_ip
is used. - $region = $r->region( [$conn] );
-
Returns the region for an IP address or hostname. If $conn is not given, the value obtained by
$r->connection->remote_ip
is used. - $city = $r->city( [$conn] );
-
Returns the city for an IP address or hostname. If $conn is not given, the value obtained by
$r->connection->remote_ip
is used. - $postal_code = $r->postal_code( [$conn] );
-
Returns the postal code for an IP address or hostname. If $conn is not given, the value obtained by
$r->connection->remote_ip
is used. - $lat = $r->latitude( [$conn] );
-
Returns the latitude for an IP address or hostname. If $conn is not given, the value obtained by
$r->connection->remote_ip
is used. - $lon = $r->longitude( [$conn] );
-
Returns the longitude for an IP address or hostname. If $conn is not given, the value obtained by
$r->connection->remote_ip
is used.
VERSION
1.11
SEE ALSO
AUTHOR
The look-up code for obtaining this information is based on the GeoIP library and the Geo::IP Perl module, and is Copyright (c) 2002, T.J. Mather, tjmather@tjmather.com, New York, NY, USA. See http://www.maxmind.com/ for details. The mod_perl interface is Copyright (c) 2002, Randy Kobes <randy@theoryx5.uwinnipeg.ca>.
All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.