Forum Moderators: coopster

Message Too Old, No Replies

How to reference include files correctly

regardless of which version of php is used

         

TravelSite

3:34 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



I use the following php code on one of my sites:

$phsyical_address=$_SERVER["DOCUMENT_ROOT"];
include ("$phsyical_address/include/connection/index.php");

It worked fine on a server using PHP5 (Apache). However it does not work on another server I have that uses PHP4 (Apache).

So I changed the line to read:

$phsyical_address=$_SERVER["PATH_TRANSLATED"];
$skip=strlen($phsyical_address)-strlen($_SERVER["PHP_SELF"]);
$phsyical_address=substr($phsyical_address,0,$skip);
include ("$phsyical_address/include/connection/index.php");

This works fine on the php4 server - but not on the php5 server :(

Is there a certain line of code that I can use that will always produce the correct result?

coopster

5:37 pm on Jun 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



DOCUMENT_ROOT should work. Have you tried dumping the variable out to the browser in both pages to see what value it contains?