doudi8298 2014-07-21 07:44
浏览 87

警告:fOpen(GeoIP.dat):无法打开流 - 仅在Wordpress博客页面上,普通页面可以吗?

I've got this function in my Wordpress theme directory:

function variable($value) {
$country_code = '';
require_once("geoip.inc");
$gi = geoip_open(dirname(__FILE__)."/GeoIP.dat",GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
switch ($value) {
    case 'prem_no':
        if ($country_code == 'US') { $prem_no = '888-888-8888'; }
        elseif ($country_code == 'AU') { $prem_no = '1900 000 000'; }
        else { $prem_no  = '0906 636 4355'; }
        return $prem_no;
        break;


    case 'prem_rate':
        if ($country_code == 'US') { $prem_rate = '$3.50'; }
        elseif ($country_code == 'AUS') { $prem_rate = '$3.96'; } 
        else { $prem_rate  = '£1.53'; }
        return $prem_rate;
        break;

    case 'local_no':
        if ($country_code == 'US') { $local_no = '755-555-5555'; }
        elseif ($country_code == 'AUS') { $local_no = '1800 000 000'; } 
        else { $local_no  = '0207 111 6311'; }
        return $local_no;
        break;


    case 'sms_no':
        if($country_code == 'AUS') { $sms_no = '1977 1977'; } 
        else { $sms_no  = '78887'; }
        return $sms_no;
        break;

    case 'sms_rate':
        if($country_code == 'AUS') { $sms_rate = '25c'; } 
        else { $sms_rate  = '£1.50'; }
        return $sms_rate;
        break;

    case 'helpline':
        if($country_code == 'US') { $helpline = '700-777-7777'; }
        elseif ($country_code == 'AUS') { $helpline = '1700 000 000'; }
        else { $helpline  = '0207 111 6210'; }
        return $helpline;
        break;

    default:
        break;
}
}

This works fine for normal pages, and loads all the files listed above, and the switch works fine. However, when I go to view the blog articles I just get a blank page with the error message:

Warning: fopen(GeoIP.dat): failed to open stream: No such file or directory in C:\wamp\www\clairvoyant\wp-content\themes\clairvoyant\geoip.inc on line 314

and I can't work out why it would be different for normal pages and blog pages.

I know there are individual PHP files, but they all use the same functions file, right?

It's the GeoIP.dat it can't find, and it was doing this before last week before I added dirname(FILE) just before the filename.

The only difference I can think of, is my permalinks have a custom structure of /blog/%postname% - could the /blog be affecting the path somehow?

Any ideas as to why it's not working as expected just on blog pages?

UPDATE:

This is relevant function inside geoip.inc:

function geoip_open($filename, $flags) {
  $gi = new GeoIP;
  $gi->flags = $flags;
  if ($gi->flags & GEOIP_SHARED_MEMORY) {
    $gi->shmid = @shmop_open (GEOIP_SHM_KEY, "a", 0, 0);
  } else {
    $gi->filehandle = fopen($filename,"rb") or die( "Oops! Can not open $filename
" );
    if ($gi->flags & GEOIP_MEMORY_CACHE) {
      $s_array = fstat($gi->filehandle);
      $gi->memory_buffer = fread($gi->filehandle, $s_array['size']);
    }
  }

  $gi = _setup_segments($gi);
  return $gi;
}

BUMP: Can anyone throw some light on this? Wordpress seems to be stripping the path of $filename when viewing blog pages. When viewing normal pages, the full path is included.

  • 写回答

1条回答 默认 最新

  • dream6120 2014-07-21 13:20
    关注

    I finally found out what was creating the different output between pages.

    The wordpress blog pages were being generated using a separate index.php file than the other pages - this was down to the way the template I'm using worked.

    On the blog index.php template, the filename was actually being hardcoded into the index file.

    Removed that, and now just the function is being used in both, all is well!

    Thanks to all for your help

    评论

报告相同问题?

悬赏问题

  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒