Search code examples
phpinclude-path

Should I include locally or remotely?


Just something I wonder about when including files:

Say I want to include a file, or link to it. Should I just for example:

include("../localfile.php");

or should I instead use

include("http://sameserver.com/but/adirect/linkto/localfile.php");

Is one better than the other? Or more secure? Or is it just personal preference?

Clearly it would be a necessity if you had a file that you would include into files in multiple directories, and THAT file includes a different file, or is there some other way of doing that?


Solution

  • Reading a file is much faster than making an HTTP request and getting the response. Never include(a_uri) if you can help it.

    Use $_SERVER['DOCUMENT_ROOT'] if you want to calculate a complete file path for your include.