PHP Includes

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

vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

Why don't you simply use absolute paths instead?

I never said relative path didn't work. I just said I want absolute path to work for php files and it already works for images and css. It seems like the problem is with the function include/require/require_once.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

I'm getting the impression from people that includes a somehow relative to the document root.
Remember this is not the case. They are relative to the location of the script being executed, the two aren't necessarily the same.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That's why I always set a var to my document root and use that var. Not dependence on $_SERVER vars or trying to figure anything out programmatically. Just tell the script where everything starts. Then use that as the starting point.
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

So why wouldn't the function include/require/require_once not work?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Because you were trying to use $_SERVER['DOCUMENT_ROOT'] when DOCUMENT_ROOT isn't present in $_SERVER.
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

You're right! I got this when displaying $_SERVER['DOCUMENT_ROOT']:
Notice: Undefined index: DOCUMENT_ROOT in C:\Inetpub\wwwroot\MySite\mf\index.php on line 15
How would I set the document root?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have a look at dirname() and pathinfo().
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

hmmm... Well I tested the absolute path and it seems to start from the C:. How can I have it start in mysite's folder? I have IIS 5.1.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What about realpath()?
Post Reply