gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:22:59 26 4
gpt4 key购买 nike

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

<?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');
}
?>

在浏览器中我得到这个错误:

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

GeoIP 安装在服务器中。我在 info.php 上查看过:geoip version 1.0.8

enter image description here

最佳答案

你不能在 php 脚本中包含 php.ini,你也不需要,因为 phpinfo() 返回它已经安装。

为了使 GeoLite 工作,您需要做的是首先包含 geoip.inc 文件 include("include/geoip.inc");

如果您还没有它,可以在这里找到它: 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');
}
?>

关于php - 如何在共享服务器上配置 GeoIP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26062507/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com