Saturday, 25 July 2009

When writing a PHP include to the web root, will this work?

define("WebRoot", "/path/to/the/web/root");





include(WebRoot . "/home.php");


include(WebRoot . "/about.php");


include(WebRoot . "/etc.php");





I want to make it so that the site I'm working on can be easily transferred to another web host if it needs to be, and I'm currently pointing all my includes to the root. If I have one definition in one location, it will save me a lot of work, I assume. Anything wrong/unsecure about using define() like this?
When writing a PHP include to the web root, will this work?
Forget the define. Use a sub folder of the root, or place the file to include in the root folder. For a sub folder use :


include ("/folder_name/filename")


For the root use :


include ("/filename")
When writing a PHP include to the web root, will this work?
I think it is a smart idea to have a Constant taht defines your path like that....I see nothing wrong with that...Just smart forethinking.


No comments:

Post a Comment