How easy is it to enable php, among other things?

I really have a problem with including php files. I need to work with a large number of folders, so it is sometimes difficult to include a php page.

ex. file in the folder: inc / chat / scripts / index.php want to include the file from php / ajax / nd.php

include("../../../php/ajax/nd.php");

So my question is, is there any other way to do this instead of using ../ all the time? (I don’t know which server will run my page in the future to set a static path).

is it better to use include or include_once (to avoid another call)?

+4
source share
3 answers

just grab the root of the document and use it.

$root = $_SERVER['DOCUMENT_ROOT'] ; 
include("$root/php/ajax/nd.php");

this file will contain the file from the root of the site / application document.

+1

-

define('BASE_PATH', '/');

-

include_once(BASE_PATH.'/rest_of_path');

../. .

0

- chdir() getcwd().

First set the project root path to chdir ("path") and use the getcwd () sibling so that you do not need to include the full path.

Refer to this question

0
source

All Articles