FQDN for 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

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

FQDN for includes

Post by Vegan »

right now I am using include "../../footer.php" etc for my web site. Clumsy but it works.

I tried FQDN and that does not work.

because I use subdirectories I cannot use /footer.php as PHP is not configured to realize the relative addressing

any suggestions?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: FQDN for includes

Post by requinix »

Code: Select all

include $_SERVER["DOCUMENT_ROOT"] . "/footer.php";

Code: Select all

include __DIR__ . "/../../footer.php"; // PHP 5.3+

Code: Select all

include dirname(__FILE__) . "/../../footer.php";
Take your pick.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: FQDN for includes

Post by Vegan »

Will I need to declare the DOCUMENT_ROOT or will PHP already be aware of it?

include $_SERVER["DOCUMENT_ROOT"] . "/footer.php";
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: FQDN for includes

Post by requinix »

DOCUMENT_ROOT is always available if you're running PHP as a server module (in Apache or IIS or whatever). I'm quite sure it's always available if you're using it as CGI too (eg, FastCGI). It is not available if the script runs from a shell or cron job.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: FQDN for includes

Post by Vegan »

thanks
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply