Forum Moderators: coopster

Message Too Old, No Replies

Best way to call a global.php file

<? require("global.php");?>

         

sauce

4:36 pm on Sep 16, 2005 (gmt 0)

10+ Year Member



I got a site with many sub-directories and I was wondering what is the best way to call a global.php for each page... <? require("global.php");?> doesn't work because pages in the sub-dirs are calling from their own directory.

<? require("/global.php");?> gives me errors...

Anyone got the correct syntax for this? I've never really used global includes on sites with sub-dirs. thx.

sauce

vdoyl

8:59 pm on Sep 16, 2005 (gmt 0)

10+ Year Member



require() is looking for a full path to the file

when you use

require('/somefile.php')

The PHP is looking for the file in the server root folder.

The best way would be to use the full server path to the file

require('/home/user/file.php')

Check the full server path to your hosting account with your web hosting provider, then use it in your require() calls.

Another option could be to use:

require($_SERVER['DOCUMENT_ROOT']."/somefile.php");

however, the latter may not work with some server setups as the DOCUMENT_ROOT variable may be different from the real server path to your web root.