SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Locker's Avatar
    Join Date
    May 2005
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_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:

    Code PHP:
    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?

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    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:

    PHP Code:
    $dir rtrim($_SERVER['DOCUMENT_ROOT'], '/');

    require 
    $dir '/header.php'


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •