The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Apache::Geo::IP::Record - Contains city information for GeoIP City Edition

SYNOPSIS

 # in httpd.conf
 # PerlModule Apache::HelloIP
 #<Location /ip>
 #   SetHandler perl-script
 #   PerlHandler Apache::HelloIP
 #   PerlSetVar GeoIPDBCityFile "/usr/local/share/GeoIP/GeoIPCity.dat"
 #   PerlSetVar GeoIPFlag Standard
 #</Location>
 
 # file Apache::HelloIP
  
 use Apache::Geo::IP::Record;
 use strict;
 
 use Apache::Constants qw(OK);
 
 sub handler {
   my $r = Apache::Geo::IP::Record->new(shift);
   $r->content_type('text/plain');
   my $city = $r->city;
 
   $r->print($city);
  
   return OK;
 }
 1;

DESCRIPTION

This module constitutes a mod_perl (version 1) interface to the Geo::IP module which contains location information returned by the GeoIP City database.

CONFIGURATION

This module subclasses Apache, and can be used as follows in an Apache module.

  # file Apache::HelloIP
  
  use Apache::Geo::IP::Record;
  use strict;
  
  sub handler {
     my $r = Apache::Geo::IP::Record->new(shift);
     # continue along
  }
 

The directives in httpd.conf are as follows:

  PerlModule Apache::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

Geo::IP and Apache.

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.