I created a file that I am wanting to use throughout the entirety of my site. This file is using a config file. The reason for my question is that I am not sure how to call the config file from sub-folders and the root files while just having this one file.
I understand that if I am in the same folder as the file that I call it like this:
require_once 'config.php';
And if I am in a sub-folder, I call it like this:
require_once '../config.php';
However, with this being one file, I need one cohesive method to call the file.
I tried the following, but received errors.
require_once '/home/{user}/config.php';
Errors:
Warning: require_once(/home/{user}/config.php): failed to open stream: No such file or directory in /home/domain/public_html/3dpdf.php on line 5
Fatal error: require_once(): Failed opening required '/home/{user}/config.php' (include_path='.:/opt/cpanel/ea-php71/root/usr/share/pear') in /home/domain/public_html/3dpdf.php on line 5
Does anyone know how I can use the require_once
method to get the config file within my files regardless of what folder it is in?
Here is an img to help show my file hierarchy. The rectangle boxes are where I will be requiring the config file. The star is next to the config file.