Problem with require() when using a fully qualified URL
20:26 11 Nov 2010

So, my code was using relative paths, but running into some problems with common files which could be include/required from different directory levels.

Absolute paths are more efficient anyway, right? So, I changed all include/require to absolute paths, using require_once('http://' . $_SERVER['HTTP_HOST'] . 'file_name.php');

$_SERVER['HTTP_HOST'] is correct, isn't it? It seemed so when I googled.

That required me to set allow_url_include=on in php.ini and restart Apache.

So, now I have a situation that looks something like this (simplified example):

File2.php contains

';
   }
?>

and if file1.php contains


then I see the expected output "hello", but if I change that line to

   require_once('http://' . $_SERVER['HTTP_HOST'] . '/file2.php');

Then I get "Fatal error: Call to undefined function hello() in C:\xampp\htdocs\file1.php"

(I guess that the reference to c:\xammp\httdos came from Xdebug, because PhpInfo shows HTTP_HOST localhost)

Anyway, that's a long post to say that I am missing some simple point and to ask what it is.

php