Page 1 of 1

Include Problem!

Posted: Fri Sep 23, 2005 1:51 am
by 99miles
Why won't this work!!!???
Both files are located in the same directory. I NEED to keep it an absolute path!

index.php:

Code: Select all

<?

include('http://localhost/snippets/Php/include_issue/library.php');

test_function();

?>
library.php:

Code: Select all

<?

echo "In File <br/>";

function test_function()
{
	echo "In Function";
}

?>
It results in:

In File
PHP Fatal error: Call to undefined function: test_function() in E:\Web\snippets\Php\include_issue\index.php on line 5

Posted: Fri Sep 23, 2005 1:59 am
by feyd
including a URL will give you the output of the URL, not the code contained inside it (if the file is processed by php)

If the file is on your server, use a local path. If not, then you are treading into quite dangerous territory including a foreign file..

Posted: Fri Sep 23, 2005 2:06 am
by 99miles
I have to use an absolute path because in my real situation, that index.php file is included by many other files. Those files can reside in any directory. The relative include path is relative to the main file that is including all the other files. Got it?

Posted: Fri Sep 23, 2005 2:48 am
by s.dot
http://www.domain.com/some/dir/file.php

is not an absolute path. It's a URL. An absolute path would look like:

/home/user/htdocs/snippets/Php/include_issue/library.php

Posted: Fri Sep 23, 2005 3:51 am
by shiznatix
and if you include it many times in other files just be like ../../file.php or whatnot since well, that is the only way to do it really