Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14574

Re: Getting the website document root portably (Apache, IIS, maybe others) and simply

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.php
Subject Re: Getting the website document root portably (Apache, IIS, maybe others) and simply
Date 2014-11-13 22:54 +0100
Organization PointedEars Software (PES)
Message-ID <2398525.OyAPUs1pPJ@PointedEars.de> (permalink)
References <m42m6j$6vd$1@dont-email.me>

Show all headers | View raw


James Harris wrote:

> This is a question that has been asked before but there seems no consensus
> in the answers given out there in internet land so I wonder if folks on
> this newsgroup can recommend a currently accepted best-practice solution.

Short answer: Do not rely on DOCUMENT_ROOT.

> What should a PHP file do in order to find out the "document root"?

Here is a better question: Why should "a PHP file" do that in the first 
place?

> I am looking for a solution that is portable across different web servers
> and OSes and is simple enough to be present verbatim on any page which
> needs such info.

Reads like a solution desperately looking for a problem.

<http://www.catb.org/~esr/faqs/smart-questions.html#goal>
 
> As for the DOCUMENT_ROOT value itself:
> 
> Page http://www.helicron.net/php-document-root/ says that IIS does not
> include DOCUMENT_ROOT in $_SERVER. The page is dated 2010. Still valid?

I do not know (fortunately, I do not have to deal with IIS since 2 years 
anymore).  If you need to support it, install IIS & friends and try it out.
 
> https://web.archive.org/web/20120112005237/http://koivi.com/apache-iis-> php-server-array.php
> says that DOCUMENT_ROOT is included in IIS. That page is dated 2012; the
> current page it just blank so I had to go to the web archive for it.

Why not go to <http://msdn.microsoft.com/> instead?  Or read the source code 
for the PHP ISAPI module.

That said, PHP with FastCGI is recommended over ISAPI nowadays, partially 
because PHP 5.4 and above do not come with an ISAPI module anymore.

You could have found that out by going to <http://php.net/> and RTFM instead 
of unearthing dead Web sites:

<http://php.net/manual/en/migration53.windows.php>
<http://php.net/manual/en/install.windows.php>
 
> […] Hence the question: is there a simple, portable way to get the web
> site's base directory in a form that is easy to use in subsequent PHP
> code?

No.

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.php | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Getting the website document root portably (Apache, IIS, maybe others) and simply "James Harris" <james.harris.1@gmail.com> - 2014-11-13 16:28 +0000
  Re: Getting the website document root portably (Apache, IIS, maybe others) and simply "J.O. Aho" <user@example.net> - 2014-11-13 18:38 +0100
    Re: Getting the website document root portably (Apache, IIS, maybe others) and simply Matthew Carter <m@ahungry.com> - 2014-11-13 14:32 -0500
      Re: Getting the website document root portably (Apache, IIS, maybe others) and simply "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-13 20:58 +0100
      Re: Getting the website document root portably (Apache, IIS, maybe others) and simply "James Harris" <james.harris.1@gmail.com> - 2014-11-13 20:06 +0000
    Re: Getting the website document root portably (Apache, IIS, maybe others) and simply crankypuss <crankypuss@nomail.invalid> - 2014-11-14 02:35 -0700
  Re: Getting the website document root portably (Apache, IIS, maybe others) and simply "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-13 21:04 +0100
  Re: Getting the website document root portably (Apache, IIS, maybe others) and simply "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-11-13 21:53 +0100
  Re: Getting the website document root portably (Apache, IIS, maybe others) and simply Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-13 22:54 +0100

csiph-web