including files

I finding it difficult to include files in my application. In my website are several folders but I will focus on three.
I have includes, variables, and clients. Within includes I have a file ‘dbconn.php’. This file also includes another file
in the the variables directly. In dbconn.php, when I use include_once('../variables/vars.php') it does not work
unless I use include_once('variables/vars.php') which I don’t understand.

Now in the clients directory, I want to include the file ‘dbconn.php’ in another file so I used include_once('../includes/dbconn.php'). With this I get an error ‘dbconn.php’ where I used include_once('variables/vars.php') unless I change it to include_once('../variables/vars.php') in dbconn.php before that file works.

Now as the second file works with this, the first file no more works with dbconn.php as it expects that the ‘vars.php’ file be included without moving up the directory. Thus it expects include_once('variables/vars.php').
By solving for one file, I get errors in the other file in the way the ‘vars.php’ file is included. I don’t understand why this happens. Need help. Thnaks.

create a variable which defines the root path:

for eg:

[php]
$base_path = ‘/var/www/html/yourproject/’;
include_once($base_path.‘variables/vars.php’)
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service