-1

我在尝试从他们的示例 PHP 脚本中调用 MAXMIND 的 geoip.dat 时遇到了一个奇怪的错误 - 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 是一个二进制文件,必须从http://dev.maxmind.com/geoip/geolite单独下载。请注意,还有一个我没有使用的 CSV 版本。

我的代码与示例脚本几乎完全相同,除了路径:

<?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) . "\n";
echo geoip_country_code_by_addr($gi, $IPaddress) . "\t" .
geoip_country_name_by_addr($gi, $IPaddress) . "\n";

geoip_close($gi);

?>

这是我的 PHP 信息输出:

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,
4

1 回答 1

2

GeoIP.dat不是 PHP 文件,因此您不能使用该include语句包含它。包括geoip.inc(无论在哪里),您的代码应该可以工作。

于 2013-04-12T03:34:12.247 回答