Doubt about include in files in previous directories [duplicate]

0

Let's say I have a file called header.php located in CMS / admin / includes. Let's say I've included this header.php file in a file called index.php located in CMS / admin.

Inside the header.php file I want to give include in a file called functions.php which is in CMS / admin (the same directory as the index.php). I should use:

<?php include "../functions.php" ?>

or just

<?php include "functions.php" ?>

Since header.php is being included in a file (index.php) that is in the same functions.php directory (CMS / admin), I should give include as if functions.php were in the same directory of header.php?

Did you understand?

    
asked by anonymous 22.01.2017 / 17:48

1 answer

0

The current directory of the first one, index.php, is assumed in all other files.

You can use only <?php include "functions.php" ?> .

However, be aware of the include_path configuration directive.

To know what it contains in this directive, you can invoke the ini_get() function.

echo ini_get('include_path');

It is important to know that if an unforeseen event, an accident happens and you have another file "functions.php" in another directory that is in the "include_path", you can load an unexpected file.

It is safer to adopt absolute paths.

    
22.01.2017 / 18:11