dsjfrkvn818747
2014-09-26 14:56
浏览 25
已采纳

如何在共享服务器上配置GeoIP?

I want to configure GeoIP to redirect domain to a subdomains according to country IP address in a shared server. I have created a custom php.ini to import geoip.so then in my index.php I added this code:

<?php
    require_once('/home/fuiba/php.ini');
    $gi = geoip_open('GeoIP.dat', GEOIP_MEMORY_CACHE);
    $country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);

    geoip_close($gi);
    $my_countries = 'fr';
    if (strtolower($country) == $my_countries) {
        header('Location: fr.fuiba.org');
    }
    $my_countriessss = 'us';
    if (strtolower($country) == $my_countriessss) {
        header('Location: en.fuiba.org');
    }
?>

In the browser I get this error:

extension=geoip.so
Fatal error: Call to undefined function geoip_open() in /home/fuiba/public_html/index.php on line 3

The GeoIP is installed in the Server. I checked it on info.php: geoip version 1.0.8.

enter image description here

图片转代码服务由CSDN问答提供 功能建议

我想配置 GeoIP 根据共享服务器中的国家/地区IP地址将域重定向到子域。 我创建了一个自定义 php.ini 来导入 geoip.so 然后在我的 index.php 中我添加了这段代码: \ n

 &lt;?php 
 require_once('/ home / fuiba / php.ini'); 
 $ gi = geoip_open('GeoIP.dat',GEOIP_MEMORY_CACHE); 
 $ country =  geoip_country_code_by_addr($ gi,$ _SERVER ['REMOTE_ADDR']); 
 
 geoip_close($ gi); 
 $ my_countries ='fr'; 
 if(strtolower($ country)== $ my_countries){
  header('Location:fr.fuiba.org'); 
} 
 $ my_countriessss ='us'; 
 if(strtolower($ country)== $ my_countriessss){
 header('Location:en.fuiba  .org'); 
} 
?&gt; 
   
 
 

在浏览器中我收到此错误:

 <  code> extension = geoip.so 
Fatal error:在第3行的/home/fuiba/public_html/index.php中调用未定义的函数geoip_open()
   
 
 

GeoIP安装在服务器中。 我在info.php上查了一下: geoip version 1.0.8

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpvr49226 2014-09-26 15:01
    已采纳

    You can't include a php.ini with a php script, and you don't need to since phpinfo() return that it's already installed.

    What you need to do in order to make GeoLite work is to first include geoip.inc file include("include/geoip.inc");

    Here is where you can find it if you don't already have it : https://github.com/maxmind/geoip-api-php/blob/master/src/geoip.inc

    <?php
       include("include/geoip.inc");
       $country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
    
        geoip_close($gi);
        $my_countries = 'fr';
        if (strtolower($country) == $my_countries) {
            header('Location: fr.fuiba.org');
        }
        $my_countriessss = 'us';
        if (strtolower($country) == $my_countriessss) {
            header('Location: en.fuiba.org');
        }
    ?>
    
    打赏 评论

相关推荐 更多相似问题