New to PHP so trying to work out how relative and absolute paths work with require.
My structure looks like:
/index.php
/inc/db_functions.php
/inc/config.php
/login/login.php
db_functions.php includes config.php using
require_once 'inc/config.php';
index.php includes db_functions.php using require_once 'inc/db_functions.php';
If the user is not logged in then the browser redirects to login.php. Originally login.php was in the root folder and used the same require once as index.php. It worked perfectly.
Now it is in its own subfolder.
I changed the require_once to use
require_once('../inc/db_connect.php');
The code worked until it got to the require_once line in db_connect.php and then failed.
I changed the require once in login.php to be:
require_once(__DIR__.'/../inc/db_connect.php');
Again it failed when it got to the require_once in db_connect.php
I changed the require_once in db_connect to be an absolute path. Again it failed.
Is there any way to deal with this as it seems that the include paths for an included file are changed by the location of the calling file ( which I guess makes sense) but how to make it more robust.