Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you can't rely on anthing in the $_SERVER array, as it's possible to you may get all sorts of values.</p> <p>So you'll need the following rules:</p> <ol> <li><p>If writing public code, put the path in a config file. Then if $_SERVER is not right on the user's server, they can overwrite it. You can help pre-complete their config using <code>DOCUMENT_ROOT</code> if you like using some simple rules (see below).</p></li> <li><p>If writing code for your own use that's only going to hop between a server or two, then assume <code>DOCUMENT_ROOT</code> is correct, and rwwrite it if you move servers and need to.</p></li> </ol> <hr> <p>How to provide the default <code>DOCUMENT_ROOT</code> if pre-compiling a config variable.</p> <ol> <li>On Apache, check <code>CONTEXT_DOCUMENT_ROOT</code>. <code>DOCUMENT_ROOT</code> is nearly always safe, but there are a couple of places where it can be wrong - and that's the case in the link you provided. If apache is using mod_alias or mod user_dir. In these cases, you need to use <code>CONTEXT_DOCUMENT_ROOT</code> which is safer. But note that Apache has only been adding <code>CONTEXT_DOCUMENT_ROOT</code> for a month or so, so unless you have the very latest install, you need to fall back on <code>DOCUMENT_ROOT</code>.</li> <li><code>DOCUMENT_ROOT</code> - see above</li> <li>Use <code>PATH_TRANSLATED</code> (less the length of <code>PHP_SELF</code>) to contruct a path to current working directory. </li> <li>Use <code>SCRIPT_FILE_NAME</code> (less the length of <code>PHP_SELF</code>) to contruct a path to current working directory. </li> <li>Use the global variable <code>__DIR__</code> to current working directory</li> </ol> <p>Then, when you have those details, check for a file you know exists in that directory - and if it does, you've probably got the right path. If not, try the next one along.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload