Include Problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
99miles
Forum Newbie
Posts: 8
Joined: Thu May 05, 2005 5:35 pm

Include Problem!

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
99miles
Forum Newbie
Posts: 8
Joined: Thu May 05, 2005 5:35 pm

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
Post Reply