no access to $_SERVER["DOCUMENT_ROOT"] what do I use?

My host does not allow access to $_SERVER["DOCUMENT_ROOT"] on my shared hosting.  I can not afford to upgrade to VPS, so I am looking for a work around.  They just changed us to new servers and it used to work so I used it for all my includes and a few other things and now my sites are broken.  Any suggestions on a way to get the document root with out using   $_SERVER["DOCUMENT_ROOT"].

FYI:  I just started learning PHP about 3 months ago.
Old Way: require($_SERVER['DOCUMENT_ROOT'] . "/noaccess/config.php");

Open in new window

LVL 1
karp13Asked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
"../../../dir/file.php" if I am calling from deeper in a directory structure.

Yeah, a nuisance for sure.  Not certain this exact string will do it for you, but it seems easy enough to try... You can set the value of the DOCUMENT_ROOT even if the server does not set it for you.  Then your old code should still be OK.
$_SERVER["DOCUMENT_ROOT"] = '\boswinfs05\home\users\web\b87\whl.karp13\';

Open in new window

0
 
Ray PaseurCommented:
Try omitting it.
0
 
Ray PaseurCommented:
Please install this little script and post a link here.  You can remove it later - I just want to see what your options might be.
<?php phpinfo(); ?>

Open in new window

0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
zappafan2k2Commented:
Is there a reason you can't use relative paths?
require('noaccess/config.php');

Open in new window

0
 
karp13Author Commented:
Thanks for the quick response Ray!

http://halfbreedcustoms.com/test/path.php
0
 
karp13Author Commented:
@Zapp

Just thought it was easier that having to add all the "../../../dir/file.php" if I am calling from deeper in a directory structure.
0
 
pitt7Commented:
The default current working directory of PHP is the directory where the .php file is in.
Include the files using a relative path.

Example:
DocRoot is /var/www
Include path is /var/www/noaccess
.php file is located in /var/www/homepage/file.php
Just include your config like
require("../noaccess/config.php");
0
All Courses

From novice to tech pro — start learning today.