gpt4 book ai didi

.htaccess - geoip 将国家重定向到 403

转载 作者:行者123 更新时间:2023-12-04 23:43:38 34 4
gpt4 key购买 nike

我在使用 geoip 阻止国家时遇到问题。当我使用我的托管帐户实用程序来阻止国家/地区时,它会在 .htaccess 中创建以下脚本。问题是它似乎不起作用(添加了美国但未被阻止)。

GeoIPEnable on
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AU$ [OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$ [OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CN$
RewriteRule ^.*$ - [F]

因此,我将 [OR] 添加到列表中的最后一个国家/地区,但现在它阻止了所有内容,包括不在列表中的国家/地区。在这里我尝试删除 US 但仍然收到 403 消息。

GeoIPEnable on
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AU$ [OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$ [OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CN$ [OR]
RewriteRule ^.*$ - [F]

最佳答案

我没有使用 .htaccess 就做到了。我只是将以下代码片段放在 header 文件中。这可能对您有帮助:

<?php 
include("includes/lcs/geoip.inc"); //Also load this file for its functions.
$serverIP=$_SERVER['REMOTE_ADDR']; //Get the IP address.
//echo $serverIP;
$gi = geoip_open("includes/lcs/GeoIP.dat",GEOIP_STANDARD); //Get the 2 letter country designation for the IP address.
$restricted_countries = array("US"); // list of restricted countries like array("NP", "US");
$country = geoip_country_code_by_addr($gi, $serverIP);


$restricted_pages = array("country_login","country_contact","country_password_forgotten","account");


if( (in_array($country,$restricted_countries)) and (!in_array($_GET['main_page'],$restricted_pages) ) )
{
header("location: https://www.yoursite.com/country_contact.html");

}
?>

这只是重定向到受限国家/地区的 country_contact.html

关于.htaccess - geoip 将国家重定向到 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16380930/

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