use of $_SERVER['DOCUMENT_ROOT'].

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    use of $_SERVER['DOCUMENT_ROOT'].

    I'm working on a large intranet group site with a lot of pages, file types,
    folders, subfolders, etc. I am using the include ('../includes/file.php') ,
    but I would like to have a single snippet that will work for all .php/.html
    pages in all subfolders. I have seen the $_SERVER['DOCUMENT_ROOT']
    indicated as a way to access the root of the website without using ../ for
    each folder you have to pass up through. However, I cannot get this to work
    for me. I've seen recommendations for it's use in FAQs, etc. online, they
    all seem to be a little bit different, but none of the formats (assign to a
    variable, etc.) work for me. We're using PHP 4.3.2

    Can someone give me some guidance on the use of this?

    Thanks,
    Chris



  • Jerry Stuckle

    #2
    Re: use of $_SERVER['DOCUMENT_ROOT'].

    Chris wrote:[color=blue]
    > I'm working on a large intranet group site with a lot of pages, file types,
    > folders, subfolders, etc. I am using the include ('../includes/file.php') ,
    > but I would like to have a single snippet that will work for all .php/.html
    > pages in all subfolders. I have seen the $_SERVER['DOCUMENT_ROOT']
    > indicated as a way to access the root of the website without using ../ for
    > each folder you have to pass up through. However, I cannot get this to work
    > for me. I've seen recommendations for it's use in FAQs, etc. online, they
    > all seem to be a little bit different, but none of the formats (assign to a
    > variable, etc.) work for me. We're using PHP 4.3.2
    >
    > Can someone give me some guidance on the use of this?
    >
    > Thanks,
    > Chris
    >
    >
    >[/color]

    Chris,

    What webserver are you using?

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Andy Jeffries

      #3
      Re: use of $_SERVER['DOCUMENT_ROOT'].

      On Tue, 09 May 2006 12:06:06 -0700, Chris wrote:[color=blue]
      > I'm working on a large intranet group site with a lot of pages, file
      > types, folders, subfolders, etc. I am using the include
      > ('../includes/file.php') , but I would like to have a single snippet that
      > will work for all .php/.html pages in all subfolders. I have seen the
      > $_SERVER['DOCUMENT_ROOT'] indicated as a way to access the root of the
      > website without using ../ for each folder you have to pass up through.[/color]

      How about I give you a different way... In your Apache VirtualHost use:

      php_value include_path .:/path/to/webroot/parent/includes/

      Then you can just use:

      include("file.p hp");

      From anywhere and it will include it from the current folder (if found),
      if not look in your /includes folder for it.

      Anyway, you can do it by parsing $_SERVER["DOCUMENT_R OOT"] to get to the
      parent, but it's much easier (and cleaner to read) by re-setting
      include_path.

      If you want to keep the current path you could do it using a single global
      file which ini_set's the include_path to include the current include_path
      and the new /includes folder. You could include that in your Apache
      virtualhost using:

      php_value auto_prepend_fi le /path/to/webroot/parent/includes/global.php

      Hope this helps.

      Cheers,


      Andy


      --
      Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
      http://www.gphpedit.org | PHP editor for Gnome 2
      http://www.andyjeffries.co.uk | Personal site and photos

      Comment

      • Chris

        #4
        Re: use of $_SERVER['DOCUMENT_ROOT'].

        Thank you Andy. We're not using Apache...the current system is Linux, but
        they have given me a Windows 2003 Server for a testing server. It just
        seems to think of the document_root as the current folder that the document
        resides in. Is there a change I need to make in the php.ini file?

        Chris

        "Andy Jeffries" <news@andyjeffr ies.co.uk> wrote in message
        news:pan.2006.0 5.09.19.51.02.3 0610@andyjeffri es.co.uk...[color=blue]
        > On Tue, 09 May 2006 12:06:06 -0700, Chris wrote:[color=green]
        >> I'm working on a large intranet group site with a lot of pages, file
        >> types, folders, subfolders, etc. I am using the include
        >> ('../includes/file.php') , but I would like to have a single snippet that
        >> will work for all .php/.html pages in all subfolders. I have seen the
        >> $_SERVER['DOCUMENT_ROOT'] indicated as a way to access the root of the
        >> website without using ../ for each folder you have to pass up through.[/color]
        >
        > How about I give you a different way... In your Apache VirtualHost use:
        >
        > php_value include_path .:/path/to/webroot/parent/includes/
        >
        > Then you can just use:
        >
        > include("file.p hp");
        >
        > From anywhere and it will include it from the current folder (if found),
        > if not look in your /includes folder for it.
        >
        > Anyway, you can do it by parsing $_SERVER["DOCUMENT_R OOT"] to get to the
        > parent, but it's much easier (and cleaner to read) by re-setting
        > include_path.
        >
        > If you want to keep the current path you could do it using a single global
        > file which ini_set's the include_path to include the current include_path
        > and the new /includes folder. You could include that in your Apache
        > virtualhost using:
        >
        > php_value auto_prepend_fi le /path/to/webroot/parent/includes/global.php
        >
        > Hope this helps.
        >
        > Cheers,
        >
        >
        > Andy
        >
        >
        > --
        > Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
        > http://www.gphpedit.org | PHP editor for Gnome 2
        > http://www.andyjeffries.co.uk | Personal site and photos
        >[/color]


        Comment

        • Jerry Stuckle

          #5
          Re: use of $_SERVER['DOCUMENT_ROOT'].

          Chris wrote:[color=blue]
          > Thank you Andy. We're not using Apache...the current system is Linux, but
          > they have given me a Windows 2003 Server for a testing server. It just
          > seems to think of the document_root as the current folder that the document
          > resides in. Is there a change I need to make in the php.ini file?
          >
          > Chris
          >
          > "Andy Jeffries" <news@andyjeffr ies.co.uk> wrote in message
          > news:pan.2006.0 5.09.19.51.02.3 0610@andyjeffri es.co.uk...
          >[color=green]
          >>On Tue, 09 May 2006 12:06:06 -0700, Chris wrote:
          >>[color=darkred]
          >>>I'm working on a large intranet group site with a lot of pages, file
          >>>types, folders, subfolders, etc. I am using the include
          >>>('../includes/file.php') , but I would like to have a single snippet that
          >>>will work for all .php/.html pages in all subfolders. I have seen the
          >>>$_SERVER['DOCUMENT_ROOT'] indicated as a way to access the root of the
          >>>website without using ../ for each folder you have to pass up through.[/color]
          >>
          >>How about I give you a different way... In your Apache VirtualHost use:
          >>
          >>php_value include_path .:/path/to/webroot/parent/includes/
          >>
          >>Then you can just use:
          >>
          >>include("file .php");
          >>
          >>From anywhere and it will include it from the current folder (if found),
          >>if not look in your /includes folder for it.
          >>
          >>Anyway, you can do it by parsing $_SERVER["DOCUMENT_R OOT"] to get to the
          >>parent, but it's much easier (and cleaner to read) by re-setting
          >>include_pat h.
          >>
          >>If you want to keep the current path you could do it using a single global
          >>file which ini_set's the include_path to include the current include_path
          >>and the new /includes folder. You could include that in your Apache
          >>virtualhost using:
          >>
          >>php_value auto_prepend_fi le /path/to/webroot/parent/includes/global.php
          >>
          >>Hope this helps.
          >>
          >>Cheers,
          >>
          >>
          >>Andy
          >>
          >>
          >>--
          >>Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
          >>http://www.gphpedit.org | PHP editor for Gnome 2
          >>http://www.andyjeffries.co.uk | Personal site and photos
          >>[/color]
          >
          >
          >[/color]

          Chris,

          That's interesting.

          I just created a file containing <?php phpinfo(); ?> in the root directory of my
          IIS test machine. It shows $_SERVER['DOCUMENT_ROOT'] to be the path to the root
          directory of my website - as expected.

          Then I moved the file to a subdirectory (actually tried three different ones at
          different levels). In each case phpinfo showed the document root to be the root
          of the website.

          This happens to be Windows 2000 instead of Windows 2003. PHP is loaded as an
          isapi module (which does make a difference).

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          Working...