PHP strange DOCUMENT_ROOT?

Those (cheap) Mass-Hosters quite often do some Apache URL-Rewriting tricks - which basically make THEIR Life easier, since there's only ONE Apache V-Host, with ONE Document-Root for all shared Websites.

Those (cheap) Mass-Hosters quite often do some Apache URL-Rewriting tricks - which basically make THEIR Life easier, since there's only ONE Apache V-Host, with ONE Document-Root for all shared Websites. To find the "real" document Root in this case: Compare DOCUMENT_ROOT to SCRIPT_FILENAME from left to right. If there are no matching Path-Components, it's such a shared host.

If it's such a shared host, remove REQUEST_URI from SCRIPT_NAME => "index. Php" in your example. Then: remove the result from above from the end of SCRIPT_FILENAME => your DOCUMENT_ROOT (/home/sitename/public_html/) Edit (Christian Sciberras): This is the right answer, but it lacks code, which I had to write anyway, so here goes: if(strpos($_SERVER'SCRIPT_FILENAME',$_SERVER'DOCUMENT_ROOT')===false){ // how it works on reseller accounts... $path=str_common(getcwd(),__FILE__); }else{ // how it normally works... $path=truepath($_SERVER'DOCUMENT_ROOT').'/'; }.

When removing REQUEST_URI from SCRIPT_NAME, don't forget that REQUEST_URI may be "/", "/index. Php", "/? Page=2" etc.And in case of rewritten URLs (mod_rewrite?

) REQUEST_URI has nothing to do with SCRIPT_NAME. – binaryLV Feb 15 at 9:24.

I would use dirname(__FILE__), dirname(dirname(__FILE__) . '/../..') or something like that to create constant DOCUMENT_ROOT which would then be used instead of $_SERVER'DOCUMENT_ROOT'.

That only works in case if hard-coded paths, something I was trying to avoid in the first place. – Christian Sciberras Feb 15 at 9:26 What's the point in using $_SERVER'DOCUMENT_ROOT' then? I.e.

, why is invalid value of $_SERVER'DOCUMENT_ROOT' a problem for you? For making paths, it does not really matter if you use server-provided $_SERVER'DOCUMENT_ROOT' or "script-calculated" constant DOCUMENT_ROOT. – binaryLV Feb 15 at 9:31 You used back double-dots to calibrate the path correctly, I cannot know how far I'm inside the web directory: __FILE__ could be /www/aaa/index.

Php as well as /www/aaa/bbb/index.php. – Christian Sciberras Feb 15 at 9:55 True. But if index.

Php (main entry file for the whole page/system) resides in /www/aaa/bbb, I would expect DOCUMENT_ROOT to point to /www/aaa/bbb rather than to some meaningless directory. – binaryLV Feb 15 at 10:37.

The document root is per virtual host. But using UserDir (e.g. ~sitename) tells the server to look elsewhere for the files to process. You will need to handle this difference if you want your script to work properly.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions