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

Posted on 2010-08-18
Last Modified: 2012-05-10
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

Question by:karp13
LVL 108

Expert Comment

by:Ray Paseur
ID: 33467302
Try omitting it.
LVL 108

Expert Comment

by:Ray Paseur
ID: 33467310
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

LVL 12

Expert Comment

ID: 33467446
Is there a reason you can't use relative paths?

Open in new window

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.


Author Comment

ID: 33467447
Thanks for the quick response Ray!

Author Comment

ID: 33467457

Just thought it was easier that having to add all the "../../../dir/file.php" if I am calling from deeper in a directory structure.

Expert Comment

ID: 33467500
The default current working directory of PHP is the directory where the .php file is in.
Include the files using a relative path.

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
LVL 108

Accepted Solution

Ray Paseur earned 500 total points
ID: 33467602
"../../../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


Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now