I encountered a strange error when trying to call MAXMIND's geoip.dat from their sample PHP script - http://dev.maxmind.com/geoip/downloadable
*Warning*: Unexpected character in input: '
in*C:\Inetpub\wwwroot\clients\geoip\GeoIP.dat*on line*983*
*Parse error*: syntax error, unexpected T_STRING
in*C:\Inetpub\wwwroot\clients\geoip\GeoIP.dat*on line*983*
Geoip.dat, a binary file, must be downloaded separately from http://dev.maxmind.com/geoip/geolite. Note that there's also a CSV version which I did not use.
My code is almost exactly the same as the sample script, except for the paths:
<?php
// This code demonstrates how to lookup the country by IP Address
include("GeoIP.dat");
// Uncomment if querying against GeoIP/Lite City.
// include("geoipcity.inc");
$IPaddress=$_SERVER['REMOTE_ADDR'];
$gi =
geoip_open("C:\Inetpub\wwwroot\clients\geoip\GeoIP.dat",GEOIP_STANDARD);
echo geoip_country_code_by_addr($gi, $IPaddress) . "\t" .
geoip_country_name_by_addr($gi, $IPaddress) . "
";
echo geoip_country_code_by_addr($gi, $IPaddress) . "\t" .
geoip_country_name_by_addr($gi, $IPaddress) . "
";
geoip_close($gi);
?>
Here's my PHP info output:
PHP Version 5.2.6
System Windows NT 5.2 build 3790
Build Date May 2 2008 18:01:20
Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared" "--with-extra-includes=C:\Program Files (x86)\Microsoft SDK\Include;C:\PROGRA~2\MICROS~2\VC98\ATL\INCLUDE;C:\PROGRA~2\MICROS~2\VC98\INCLUDE;C:\PROGRA~2\MICROS~2\VC98\MFC\INCLUDE" "--with-extra-libs=C:\Program Files (x86)\Microsoft SDK\Lib;C:\PROGRA~2\MICROS~2\VC98\LIB;C:\PROGRA~2\MICROS~2\VC98\MFC\LIB"
Server API ISAPI
Virtual Directory Support enabled
Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\Parallels\Plesk\Additional\PleskPHP5\php.ini
PHP API 20041225
PHP Extension 20060613
Zend Extension 220060519
Debug Build no
Thread Safety enabled
Zend Memory Manager enabled
IPv6 Support enabled
Registered PHP Streams php, file, data, http, ftp, compress.zlib, https, ftps
Registered Stream Socket Transports tcp, udp, ssl, sslv3, sslv2, tls
Registered Stream Filters convert.iconv.*, string.rot13, string.toupper, string.tolower,
GeoIP.dat
is not a PHP file, so you cannot include it using the include
statement. Include geoip.inc
(wherever that is) instead, and your code should work.