Page 1 of 1
FQDN for includes
Posted: Mon Apr 16, 2012 4:48 pm
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?
Re: FQDN for includes
Posted: Tue Apr 17, 2012 12:55 am
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.
Re: FQDN for includes
Posted: Tue Apr 17, 2012 2:12 pm
by Vegan
Will I need to declare the DOCUMENT_ROOT or will PHP already be aware of it?
include $_SERVER["DOCUMENT_ROOT"] . "/footer.php";
Re: FQDN for includes
Posted: Tue Apr 17, 2012 4:52 pm
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.
Re: FQDN for includes
Posted: Tue Apr 17, 2012 8:58 pm
by Vegan
thanks