开发者

GeoIP & fopen() - "fopen(GeoIP/GeoIP.dat) [function.fopen]: failed to open stream" occurs even though file is there?

I've been trying to debug this error for over three hours now, changing filenames, trying to use GeoIP Lite instead of GeoCity (the latter has a 27mb file to be included, so did this thinking fopen() had a max), etc.

Here's my structure file structure: index.php -> include("configuration/config.php") - config.php -> include("inc/geo_text.php") -> geo_text.php

The contents of geo_text.php is:

$ip = $_SERVER['REMOTE_ADDR'];
include("GeoIP/geoip.inc");
$gi = geoip_open("GeoIP/GeoIP.dat",GEOIP_STANDARD);
$count_name = geoip_country_name_by_addr($gi, $ip);
geoip_close($gi);

echo($count_name);

Now, if I access geo_text.php no errors are given, and just to make sure I placed echo($count_name) in geo_text.php and it returned, as it should, my country.

However, when I run config.php it r开发者_如何学运维eturns the error:

Warning: fopen(GeoIP/GeoIP.dat) [function.fopen]: failed to open stream: No such file or directory in /nfs/c09/h02/mnt/177978/domains/domain.com/html/labs/final/configuration/inc/GeoIP/geoip.inc on line 399 Can not open GeoIP/GeoIP.dat

Has anyone got any ideas why this could be?


SSH into your server and run the following command (assuming it's a Linux server):

cd /nfs/c09/h02/mnt/177978/domains/domain.com/html/labs/final/configuration/inc/GeoIP/
ls -lah

Then paste the output here for us to see. My guess is that that path doesn't exist.


That's very strange. As a test, try moving both geo files into the same directory as your code files and then alter the paths in your code accordingly.


It's checking for the files in domain.com, but you just cd'd into themeplated.com, that's the problem. Your code needs to point to the themeplated.com directory.

/nfs/c09/h02/mnt/177978/domains/domain.com/html/labs/final/configuration/inc/GeoIP/ /nfs/c09/h02/mnt/127878/domains/themeplated.com/html/labs/final/c‌​onfiguration/inc/GeoIP/


It's a path issue.

geoip_open("/absolute/path/to/GeoIP/GeoIP.dat",GEOIP_STANDARD);

should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜