I’ve been using the $_SERVER[“DOCUMENT_ROOT”] environment variable to refer to the public root in my apps. Now I’m realizing that that’s not very reliable. I’m thinking about an approach where I define a constant in my index.php based on a magic constant. Something like that:
define("PUBILC", __DIR__."/");
I’m not sure about it though.
What approach would you recommend?
If everything request goes through your index.php, defining a constant there would be a fine, and often used, idea. I’ve also seen setups defining an environmental variable with (virtual)host configuration or .htaccess, but I think its less transparent and less portable. Hardcoding paths in a settings variable is often used but less ‘altering automatically’ then one would hope. All in all I agree with your idea.