Solved

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

Posted on 2010-08-18
8
397 Views
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

0
Comment
Question by:karp13
8 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 33467302
Try omitting it.
0
 
LVL 109

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

0
 
LVL 12

Expert Comment

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

Open in new window

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:karp13
ID: 33467447
Thanks for the quick response Ray!

http://halfbreedcustoms.com/test/path.php
0
 
LVL 1

Author Comment

by:karp13
ID: 33467457
@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
 
LVL 3

Expert Comment

by:pitt7
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.

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

Accepted Solution

by:
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

0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

770 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