我正在使用我在http://www.phptutorial.info/iptocountry/the_script.html
找到的脚本您可以看到此脚本允许我们通过识别其IP地址来阻止某个国家/地区。
完整的脚本是
$website_mode = "live"; // Set this to live to let the country blocking code work
function iptocountry($ip){
$numbers = explode( ".", $ip);
include("ip_files/".$numbers[0].".php");
$code = ($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]);
foreach($ranges as $key => $value){
if($key<=$code){
if($ranges[$key][0]>=$code){
$country=$ranges[$key][1];
break;
}
}
}
if($country==""){
$country="unknown";
}
return $country;
}
if($website_mode == "live"){
$gbc = $pdo->prepare("SELECT bc_countries FROM blocked_countries");
$gbc-> execute();
$gbf = $gbc->fetch();
$countries_to_block = explode(',', $gbf['bc_countries']);
if($_SERVER['HTTP_X_FORWARDED_FOR']){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip = $_SERVER['REMOTE_ADDR'];
}
$two_letter_country_code = iptocountry($ip);
if(in_array($two_letter_country_code, $countries_to_block)){
die("<center style='margin-top: 150px'><img src='images/stop.png' width='auto' height='200px'><br><br>*** Your country has been banned from accessing this website for security reasons ***</center>");
}
}
在这里,我编写了一个脚本来处理我在http://azuliadesigns.com/blocking-website-access-country-php/上找到的代码。我修改了一下,以便它适用于我的数据库。但是在实时网站上它返回了以下错误。
Warning: include(ip_files/2405:204:4008:c78:d485:aba6:1eb4:9d6c, 2405:204:4008:c78:d485:aba6:1eb4:9d6c.php): failed to open stream: No such file or directory in /storage/supergens5cfqqgc/files/redd.supergenscript.com/functions.php on line 11
Warning: include(ip_files/2405:204:4008:c78:d485:aba6:1eb4:9d6c, 2405:204:4008:c78:d485:aba6:1eb4:9d6c.php): failed to open stream: No such file or directory in /storage/supergens5cfqqgc/files/redd.supergenscript.com/functions.php on line 11
Warning: include(): Failed opening 'ip_files/2405:204:4008:c78:d485:aba6:1eb4:9d6c, 2405:204:4008:c78:d485:aba6:1eb4:9d6c.php' for inclusion (include_path='.:/opt/php-fpm-5.6.29-1/lib/php') in /storage/supergens5cfqqgc/files/redd.supergenscript.com/functions.php on line 11
Warning: Invalid argument supplied for foreach() in /storage/supergens5cfqqgc/files/redd.supergenscript.com/functions.php on line 13
我刚刚正确地遵循了所有程序。此外,我已经多次重新检查了所有代码,但我不确定是什么导致了这个错误。