Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP strange DOCUMENT_ROOT
    text
    copied!<p>So basically, I'm writing a framework, and as part of it features, it's supposed to provide a set of well-established URIs/paths to the end-developer.</p> <p>Some two of these paths make use of <code>$_SERVER['DOCUMENT_ROOT']</code>:</p> <pre><code>/** * Absolute filesystem path to web root install (aka docroot). * @example "C:/wamp/www" OR "/home/visitgoz/public_html/" */ CFG::set('ABS_WWW', str_replace( $tmpseps, DIRECTORY_SEPARATOR, truepath($_SERVER['DOCUMENT_ROOT']).'/' ) ); /** * K2F path relative to web root. * @example /K2F/ */ CFG::set('REL_K2F', str_replace( array('//','\\'), '/', str_replace(CFG::get('ABS_WWW'),'/',CFG::get('ABS_K2F')) ) ); </code></pre> <p>The code has been fine-tuned to work on both Linux and Windows. Apparently, it works <em>most</em> of the time on Linux, quite seamless in fact on VPSes.</p> <p>However, as of late, I tried it on an <a href="http://www.hostgator.com/resellers.shtml" rel="nofollow">HG Reseller Account</a> (shared hosting) and it all broke up. I've printed out data inside $_SERVER on the problematic machine:</p> <pre><code>Array ( ** [DOCUMENT_ROOT] =&gt; /usr/local/apache/htdocs [GATEWAY_INTERFACE] =&gt; CGI/1.1 [HTTP_ACCEPT] =&gt; text/html,application/xhtml+xml,application/xml;q=0.9;q=0.8 [HTTP_ACCEPT_CHARSET] =&gt; ISO-8859-1,utf-8;q=0.7,*;q=0.7 [HTTP_ACCEPT_ENCODING] =&gt; gzip,deflate [HTTP_ACCEPT_LANGUAGE] =&gt; en-gb,en;q=0.5 [HTTP_CONNECTION] =&gt; keep-alive [HTTP_COOKIE] =&gt; &lt;snip&gt; [HTTP_HOST] =&gt; &lt;snip&gt; [HTTP_KEEP_ALIVE] =&gt; 115 [HTTP_USER_AGENT] =&gt; &lt;snip&gt; [PATH] =&gt; /bin:/usr/bin [QUERY_STRING] =&gt; [REDIRECT_STATUS] =&gt; 200 [REMOTE_ADDR] =&gt; &lt;snip&gt; [REMOTE_PORT] =&gt; 49262 [REQUEST_METHOD] =&gt; GET [REQUEST_URI] =&gt; /~sitename/ ** [SCRIPT_FILENAME] =&gt; /home/sitename/public_html/index.php [SCRIPT_NAME] =&gt; /~sitename/index.php [SERVER_ADDR] =&gt; &lt;snip&gt; [SERVER_ADMIN] =&gt; &lt;snip&gt; [SERVER_NAME] =&gt; &lt;snip&gt; [SERVER_PORT] =&gt; 80 [SERVER_PROTOCOL] =&gt; HTTP/1.1 [SERVER_SIGNATURE] =&gt; Apache mod_fcgid/2.3.5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at &lt;snip&gt; Port 80 [SERVER_SOFTWARE] =&gt; Apache mod_fcgid/2.3.5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 [UNIQUE_ID] =&gt; TVox-Eo1Z8IAAG1kAh4AAAEZ [PHP_SELF] =&gt; /~sitename/index.php [REQUEST_TIME] =&gt; 1297756668 [argv] =&gt; Array ( ) [argc] =&gt; 0 ) </code></pre> <p>And my machine:</p> <pre><code>Array ( [HTTP_AUTHORIZATION] =&gt; [HTTP_HOST] =&gt; &lt;snip&gt; [HTTP_USER_AGENT] =&gt; &lt;snip&gt; [HTTP_ACCEPT] =&gt; text/html,application/xhtml+xml,application/xml;q=0.9;q=0.8 [HTTP_ACCEPT_LANGUAGE] =&gt; en-gb,en;q=0.5 [HTTP_ACCEPT_ENCODING] =&gt; gzip,deflate [HTTP_ACCEPT_CHARSET] =&gt; ISO-8859-1,utf-8;q=0.7,*;q=0.7 [HTTP_KEEP_ALIVE] =&gt; 115 [HTTP_CONNECTION] =&gt; keep-alive [PATH] =&gt; &lt;snip&gt; [SystemRoot] =&gt; C:\Windows [COMSPEC] =&gt; C:\Windows\system32\cmd.exe [PATHEXT] =&gt; .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC [WINDIR] =&gt; C:\Windows [SERVER_SIGNATURE] =&gt; [SERVER_SOFTWARE] =&gt; Apache/2.2.11 (Win32) PHP/5.3.1 [SERVER_NAME] =&gt; &lt;snip&gt; [SERVER_ADDR] =&gt; &lt;snip&gt; [SERVER_PORT] =&gt; 80 [REMOTE_ADDR] =&gt; &lt;snip&gt; ** [DOCUMENT_ROOT] =&gt; C:/wamp/www/ [SERVER_ADMIN] =&gt; admin@localhost ** [SCRIPT_FILENAME] =&gt; C:/wamp/www/K2F/cms/cms-joomla-1.5/index.php [REMOTE_PORT] =&gt; 49947 [GATEWAY_INTERFACE] =&gt; CGI/1.1 [SERVER_PROTOCOL] =&gt; HTTP/1.1 [REQUEST_METHOD] =&gt; GET [QUERY_STRING] =&gt; [REQUEST_URI] =&gt; /K2F/cms/cms-joomla-1.5/ [SCRIPT_NAME] =&gt; /K2F/cms/cms-joomla-1.5/index.php [PHP_SELF] =&gt; /K2F/cms/cms-joomla-1.5/index.php [REQUEST_TIME] =&gt; 1297758541 ) </code></pre> <p>** Parts you ought to read out, should explain my problem perfectly.</p> <p>So basically, the expected <code>DOCUMENT_ROOT</code> is <code>/home/sitename/public_html/</code>, but instead I got <code>/usr/local/apache/htdocs</code>.</p> <p>Oh, and sorry if I've been a bit too verbose ;)</p> <p><strong>Edit:</strong></p> <p><code>getcwd()</code> => <code>/home/visitgoz/public_html</code></p> <p><code>__FILE__</code> => <code>/home/visitgoz/public_html/K2F/config.php</code></p>
 

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