Reputation: 7687
I am having trouble trying to get a file to be included into a php script. This file is stored in the root folder, which is not the actual web root, but the root directory that I have access to via the shared hosting account.
I have created a folder in this directory that stores php session data, the .htaccess configuration regarding this would be the following line:
php_value session.save_path "/usr/home/accountname/sessions"
The web root would be stored in this directory:
/usr/home/accountname/public_html/domainname/
What I am trying to do is secure the scipt that holds database connection details, in a folder that would be something like this:
/usr/home/accountname/includes/
This is how i currently include the file:
require_once $_SERVER['DOCUMENT_ROOT'].'/includes/config.php';
I have tried this:
require_once $_SERVER['PATH'].'/usr/home/accountname/includes/config.php';
As $_SERVER['PATH']
points to /bin
This is not working as the page comes out blank, this would mean that the variables defined in config.php
are not active as the page has not been included.
Could anyone provide some information regarding this matter, or point me in the direction of solving the problem. Also, any tutorials or other info regarding this would be greatly appreciated.
Thank you!
Upvotes: 0
Views: 2950
Reputation: 14343
If the script including config.php is stored under your Web root, you can write:
require_once dirname(__FILE__) . '/../../includes/config.php';
Have you already tried?
Upvotes: 3
Reputation: 128991
If your script is in /usr/home/accountname/public_html/domainname/something.php
, you could use this:
require_once(dirname(dirname(dirname(__FILE__))).PATH_SEPARATOR."includes".PATH_SEPARATOR."config.php");
Upvotes: 1