PHP require_once目录问题

I have a website with the following directory structure:

index.php
connections/database.php
contacts/details.php
inc/functions.php

I would like the database.php page to use require_once to include the functions.php page e.g:

require_once 'inc/functions.php';

I would like to then use require_once for the both the index.php page and the details.php page to just require the database.php page which in turn will also include the functions.php page. I can get this working for either the index.php page or the details.php page but not both as I have to keep changing the syntax, e.g.

require_once 'inc/functions.php';
require_once '../inc/functions.php';

Otherwise I get errors that the functions.php page cannot be found. Is there a way to include the database.php page which also includes the functions.php page that will work from the different directories for both the index.php page and the contacts/details.php page?

thanks

Your best bet is to set a $basepath variable in your config file pointing to the absolute root path of your app. Then you can go with require_once $baseapth."/inc/functions.php"

You can use dirname(__FILE__)!