Results 1 to 2 of 2
May 11, 2009, 04:00 #1
$_SERVER['DOCUMENT_ROOT'] platform differences
I've noticed that whilst developing on a Windows XP machine with WAMP, $_SERVER['DOCUMENT_ROOT'] returns "/dir/path/". However, on my Unix servers it returns "/dir/path" (no trailing slash).
This becomes a problem as something like the following:
require($_SERVER['DOCUMENT_ROOT'] . "/header.php");
Works on the Unix server, but not in Windows...
Is this a commonly known difference and what's the best way to get around it?
May 11, 2009, 04:15 #2
- Join Date
- Mar 2002
- Bristol, UK
- 0 Post(s)
- 0 Thread(s)
The following code will strip the trailing slash off the end of the path if there is one. If not, it'll leave it alone:
$dir = rtrim($_SERVER['DOCUMENT_ROOT'], '/');
require $dir . '/header.php';