SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_server['document_root']

    On my local site, $_SERVER['DOCUMENT_ROOT'] returns C:/xampp/htdocs. Shouldn't it also add /mysite?
    My includes work when I do this:
    include $_SERVER['DOCUMENT_ROOT'].'/mysite/includes/myfunctions.php';
    But won't that cause a problem when I publish my site? I didn't think that /mysite should be in the include.
    If this is a problem, how do I fix it?

    Robert

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    What's the document root specified in your httpd.conf/httpd-vhosts.conf? That's the document root, it's not an alias for the current directory.

    I always have some kind of front controller or dispatcher in my applications, so that's where I define the root using dirname(__FILE__), so it's relative to the front controller.

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This is a common issue, and its solution depends on your application architecture.

    Document Root is not the path to your project directory, its the path to the server base directory - i.e. the directory that http://localhost/ maps to.

    My typical application works by routing every request to index.php. Therefore I simply use __DIR__ in index.php to get the root.

    Would it not make more sense to use a relative path?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


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
  •