This is my first time moving a locally-hosted PHP site to a hosting service. My site is built with the inc folder (which includes the database constants) outside of the web root, so on my local machine it's in
XAMPP/xamppfiles/htdocs/inc/
and the rest of the files, including the common/ directory, are in
XAMPP/xamppfiles/htdocs/mydomain/
Most of the pages call
include_once "common/base.php";
which lives inside
htdocs/mydomain/common/
and which includes the database constants by calling
include_once $_SERVER['DOCUMENT_ROOT'] . "/inc/constants.inc.php";
On my local site, $_SERVER['DOCUMENT_ROOT'] outputs "Applications/XAMPP/xamppfiles/htdocs/", and the inc files are found.
Unfortunately, on the DotEasy site, the files aren't being found. If I echo $_SERVER['DOCUMENT_ROOT'], the output is "/home/myusername/public_html".
I'm able to get to the inc/ directory by this:
$temp_path = $_SERVER['DOCUMENT_ROOT'];
$temp_path = str_replace('public_html', '', $temp_path);
include_once $temp_path . "/inc/constants.inc.php";
but is this a good idea? Am I wrong to worry about having the constants in the public_html folder?
inc
folder, and instead of doing the wholestr_replace
thing, just give it a relative path (../constants.inc.php
). – Ansari