从PHP5调用MAXMIND geoip.dat时出现意外的字符/ T_STRING错误(Windows)[关闭]

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,
php
duancong2965
duancong2965 无论谁说你应该包含.dat文件?!如果他们这样做,那是无稽之谈。
大约 7 年之前 回复

1个回答



GeoIP.dat </ code>不是PHP文件,所以你不能使用 include <包含它 / code>声明。 包括 geoip.inc </ code>(无论在哪里),您的代码应该有效。</ p>
</ div>

展开原文

原文

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问