config.php put at the root level, this file will be included in any pages.
Then at config.php
<?php
define( 'ROOT_DIR', dirname(__FILE__) );
?>
So at all other pages from different sub/a.php , sub/sub/b.php directories, when I want to include a specific file in specific location, I just need to
include( ROOT_DIR.'/include/functions.php' );
In windows server, the ROOT_DIR bring the value to C:/inetpub/vhosts/domain.com
Is this a good/secure way?
It seems like via this way, when I move the b.php to other upper level folder, I don’t need to do any changes to the include file path, which is good for maintenance.
Any cons? Like SEO wise, or any other reason…
What you guys think.
I will comment that one advantage to the method you’re using (using absolute paths) is that PHP won’t need to resolve the path for every request. You may see ever-so-slightly better performance that way.
Also, if you’re using PHP 5.3, you can just use
__DIR__instead ofdirname(__FILE__).If you’re not using 5.3, you might give it a shot if you can. A lot of improvements were made for the Windows platform in 5.3, not to mention the many new useful language features.