Reputation: 651
Due to path issues, I changed my php site to have the following statement at least once on each page:
include($_SERVER['DOCUMENT_ROOT'] . "/path/file.php");
Are there any concerns (mainly security) that I should have using this approach?
(before I just used: include("/path/file.php");
)
Upvotes: 5
Views: 944
Reputation: 36299
I have never heard of any concerns when using that, but I prefer doing this:
require_once __DIR__ . "/path/to/file/from/current/filephp";
I do this, because we don't always know if there will be a document root, but we do know that the current file does have a current directory.
Upvotes: 0
Reputation: 7409
As PHP is parsed exclusively on the server, using $_SERVER['DOCUMENT_ROOT']
will never be passed to the client and doesn't create a security issue.
However, like all $_SERVER
variables, $_SERVER['DOCUMENT_ROOT']
is only made available by your webserver and running these scripts in a command line environment will cause an undefined error.
Upvotes: 4