PHP error help

software development

#1

Hi, I have a small piece of php code to add to my existing php file.

It give an error and I have brought it back to 1 line:

include(“ip_files/”.$numbers[0].".php");
the error show:

Warning: include(ip_files/.php) [function.include]: failed to open stream: No such file or directory in …

Which suggests to me that the php code “.$numbers[0].” does not works to view the different 259 files in that folder (ip_files). I tested it by doing include(“ip_files/10.php”); and the error was gone.

Any replacement code for that, since the script is from 2009?

This is also regarding thread https://discussion.dreamhost.com/thread-138396.html , but this question should be here.


#2

What it suggests is the value of $numbers[0] is empty or not defined.

Having said that, where is the $numbers array values set?


#3

Even your question goes above my knowledge, sorry.

This is the complete code I added to the existing php:

[code]if ($_SERVER[‘HTTP_X_FORWARDED_FOR’])
$ip = $_SERVER[‘HTTP_X_FORWARDED_FOR’];
else
$ip = $_SERVER[‘REMOTE_ADDR’];

$two_letter_country_code=iptocountry($ip);

function iptocountry($ip)
{
$numbers = preg_split( “/./”, $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;
}

session_start();
if (!isset($_SESSION[‘FirstVisit’]))
{
if ($two_letter_country_code==“US”)
die();
else
$_SESSION[‘FirstVisit’] = 1;
}[/code]

Of course I could always do:
include(“ip_files/01.php”);
include(“ip_files/02.php”);
include(“ip_files/03.php”);
all the way up to 259, but that seems not the right way.


#4

Either you are not running the script in a web server environment, PHP is not able to access the web server variables, the value the web server/PHP is passing for the IP address is not what is expected, or the function preg_split() is not being called correctly. It could also be a flaw in the code that determines which variable to get the IP address from; most of the time isset() is called to determine if a variable has a value.


#5

Thanks for your help, even if I don’t understand any of it.

Anyway I found a replacement code

foreach (glob(“ip_files/*.php”) as $filename)
{
include $filename;
}

which gets rid of the error, but after several tests, the website just does not get blocked for me.

I also tried a straight forward .htaccess block (my IP) and that did not block the website for me.

So I am tempted to give up on the whole blocking idea.