I am working on a web application that uses PHP and JavaScript and I have some troubles accessing some pages that are not on the root if they are including other files (ie. ‘include once’).
[file system]/www/project/test/test.php
The project folder has the index.php. Here is an example of my code:
include_once('../config/config.php');
include_once('../database/database.php');
echo 'Test.php';
$config = new Config();
$dbhandle = new Database();
[...]
What am I doing wrong here?
The error log from Apache tells me that there is no file config.php and database.php.
use $_SERVER[‘DOCUMENT_ROOT’] to relocate the path to the root path of your server like this :
So now all your path are Absolute and not relative.
Hope that helps.
PS : You can also get confortable using a php framework that will do the magic of routing your dependencies easier on a bigger project.