Determining document root when $_SERVER['DOCUMENT_ROOT'] is not an option

This is a discussion on Determining document root when $_SERVER['DOCUMENT_ROOT'] is not an option within the PHP Language forums, part of the PHP Programming Forums category; Hi, We're using PHP 4.4.4 with Apache 2 on Linux. Aggravatingly, the hosting company has done something ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-26-2007
laredotornado@zipmail.com
 
Posts: n/a
Default Determining document root when $_SERVER['DOCUMENT_ROOT'] is not an option

Hi,

We're using PHP 4.4.4 with Apache 2 on Linux. Aggravatingly, the
hosting company has done something to where $_SERVER['DOCUMENT_ROOT']
no longer returns the path to the web root directory. I have now gone
through all my code and replaced $_SERVER['DOCUMENT_ROOT'] with a
constant, DOC_ROOT. Now, the challenge is to define the constant.

Suggestions?

One important thing. The file the constant will be defined in is not
necessarily going to be a file at the web root level.

Thanks for all your help, - Dave

Reply With Quote
  #2 (permalink)  
Old 06-26-2007
ZeldorBlat
 
Posts: n/a
Default Re: Determining document root when $_SERVER['DOCUMENT_ROOT'] is not an option

On Jun 26, 3:55 pm, "laredotorn...@zipmail.com"
<laredotorn...@zipmail.com> wrote:
> Hi,
>
> We're using PHP 4.4.4 with Apache 2 on Linux. Aggravatingly, the
> hosting company has done something to where $_SERVER['DOCUMENT_ROOT']
> no longer returns the path to the web root directory. I have now gone
> through all my code and replaced $_SERVER['DOCUMENT_ROOT'] with a
> constant, DOC_ROOT. Now, the challenge is to define the constant.
>
> Suggestions?
>
> One important thing. The file the constant will be defined in is not
> necessarily going to be a file at the web root level.
>
> Thanks for all your help, - Dave


Does you web root change? Are you planning on deploying the software
to another server? If the answer is no just hard code it in some
configuration file. You do have a configuration file of sorts for
database connection parameters and such, right?

Reply With Quote
  #3 (permalink)  
Old 06-26-2007
laredotornado@zipmail.com
 
Posts: n/a
Default Re: Determining document root when $_SERVER['DOCUMENT_ROOT'] is not an option

On Jun 26, 3:26 pm, ZeldorBlat <zeldorb...@gmail.com> wrote:
> On Jun 26, 3:55 pm, "laredotorn...@zipmail.com"
>
> <laredotorn...@zipmail.com> wrote:
> > Hi,

>
> > We're using PHP 4.4.4 with Apache 2 on Linux. Aggravatingly, the
> > hosting company has done something to where $_SERVER['DOCUMENT_ROOT']
> > no longer returns the path to the web root directory. I have now gone
> > through all my code and replaced $_SERVER['DOCUMENT_ROOT'] with a
> > constant, DOC_ROOT. Now, the challenge is to define the constant.

>
> > Suggestions?

>
> > One important thing. The file the constant will be defined in is not
> > necessarily going to be a file at the web root level.

>
> > Thanks for all your help, - Dave

>
> Does you web root change? Are you planning on deploying the software
> to another server? If the answer is no just hard code it in some
> configuration file. You do have a configuration file of sorts for
> database connection parameters and such, right?


We do have a config file for the db connection stuff, but the problem
is on our dev server, the site is located one level down from the web
root and on the live site it is located at the same level. So it
would be great to find an expression to cover both situations.

Thanks, -

Reply With Quote
  #4 (permalink)  
Old 06-26-2007
Alvaro G. Vicario
 
Posts: n/a
Default Re: Determining document root when $_SERVER['DOCUMENT_ROOT'] is not an option

*** laredotornado@zipmail.com escribió/wrote (Tue, 26 Jun 2007 12:55:15
-0700):
> We're using PHP 4.4.4 with Apache 2 on Linux. Aggravatingly, the
> hosting company has done something to where $_SERVER['DOCUMENT_ROOT']
> no longer returns the path to the web root directory. I have now gone
> through all my code and replaced $_SERVER['DOCUMENT_ROOT'] with a
> constant, DOC_ROOT. Now, the challenge is to define the constant.
>
> Suggestions?


If you have your own php.ini file (many ISPs offer this possibility), then
you can fill the DOCUMENT_ROOT variable to suit your needs:

::: php.ini :::

auto_prepend_file = /home/foo/phpconfig.php


::: phpconfig.php :::

<?php

$_SERVER['DOCUMENT_ROOT'] = '/home/foo/whatever';

?>



--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Reply With Quote
  #5 (permalink)  
Old 06-26-2007
gosha bine
 
Posts: n/a
Default Re: Determining document root when $_SERVER['DOCUMENT_ROOT'] is notan option

laredotornado@zipmail.com wrote:
> On Jun 26, 3:26 pm, ZeldorBlat <zeldorb...@gmail.com> wrote:
>> On Jun 26, 3:55 pm, "laredotorn...@zipmail.com"
>>
>> <laredotorn...@zipmail.com> wrote:
>>> Hi,
>>> We're using PHP 4.4.4 with Apache 2 on Linux. Aggravatingly, the
>>> hosting company has done something to where $_SERVER['DOCUMENT_ROOT']
>>> no longer returns the path to the web root directory. I have now gone
>>> through all my code and replaced $_SERVER['DOCUMENT_ROOT'] with a
>>> constant, DOC_ROOT. Now, the challenge is to define the constant.
>>> Suggestions?
>>> One important thing. The file the constant will be defined in is not
>>> necessarily going to be a file at the web root level.
>>> Thanks for all your help, - Dave

>> Does you web root change? Are you planning on deploying the software
>> to another server? If the answer is no just hard code it in some
>> configuration file. You do have a configuration file of sorts for
>> database connection parameters and such, right?

>
> We do have a config file for the db connection stuff, but the problem
> is on our dev server, the site is located one level down from the web
> root and on the live site it is located at the same level. So it
> would be great to find an expression to cover both situations.
>
> Thanks, -
>


How about

if(DEV_SERVER)
define('DOC_ROOT', 'something');
else
define('DOC_ROOT', 'something else');


where DEV_SERVER could be, for example,

define('DEV_SERVER', $_SERVER['SERVER_ADDR'] == "127.0.0.1");

or something else specific to your environment.



--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Reply With Quote
  #6 (permalink)  
Old 06-27-2007
shimmyshack
 
Posts: n/a
Default Re: Determining document root when $_SERVER['DOCUMENT_ROOT'] is not an option

On Jun 26, 10:33 pm, gosha bine <stereof...@gmail.com> wrote:
> laredotorn...@zipmail.com wrote:
> > On Jun 26, 3:26 pm, ZeldorBlat <zeldorb...@gmail.com> wrote:
> >> On Jun 26, 3:55 pm, "laredotorn...@zipmail.com"

>
> >> <laredotorn...@zipmail.com> wrote:
> >>> Hi,
> >>> We're using PHP 4.4.4 with Apache 2 on Linux. Aggravatingly, the
> >>> hosting company has done something to where $_SERVER['DOCUMENT_ROOT']
> >>> no longer returns the path to the web root directory. I have now gone
> >>> through all my code and replaced $_SERVER['DOCUMENT_ROOT'] with a
> >>> constant, DOC_ROOT. Now, the challenge is to define the constant.
> >>> Suggestions?
> >>> One important thing. The file the constant will be defined in is not
> >>> necessarily going to be a file at the web root level.
> >>> Thanks for all your help, - Dave
> >> Does you web root change? Are you planning on deploying the software
> >> to another server? If the answer is no just hard code it in some
> >> configuration file. You do have a configuration file of sorts for
> >> database connection parameters and such, right?

>
> > We do have a config file for the db connection stuff, but the problem
> > is on our dev server, the site is located one level down from the web
> > root and on the live site it is located at the same level. So it
> > would be great to find an expression to cover both situations.

>
> > Thanks, -

>
> How about
>
> if(DEV_SERVER)
> define('DOC_ROOT', 'something');
> else
> define('DOC_ROOT', 'something else');
>
> where DEV_SERVER could be, for example,
>
> define('DEV_SERVER', $_SERVER['SERVER_ADDR'] == "127.0.0.1");
>
> or something else specific to your environment.
>
> --
> gosha bine
>
> extended php parser ~http://code.google.com/p/pihipi
> blok ~http://www.tagarga.com/blok


I would define the absolute path to the application root using:

define('ABSPATH', dirname(__FILE__).'/');

But I have come across this problem when using Dynamically Configured
Mass Virtual Hosting, and although you havent said, it may be
returning the IP instead of the servername withint the path:

should be
/path/to/vhosts/servername.com/htdocs
but is
/path/to/vhosts/IP_OF_SERVER/htdocs
instead, in this case yuo can just do a string replace
$_SERVER["SERVER_ADDR"]
with
$_SERVER["SERVER_NAME"]
with the
$_SERVER["DOCUMENT_ROOT"]
variable

Reply With Quote
  #7 (permalink)  
Old 06-27-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Determining document root when $_SERVER['DOCUMENT_ROOT'] is notan option

laredotornado@zipmail.com wrote:
> Hi,
>
> We're using PHP 4.4.4 with Apache 2 on Linux. Aggravatingly, the
> hosting company has done something to where $_SERVER['DOCUMENT_ROOT']
> no longer returns the path to the web root directory. I have now gone
> through all my code and replaced $_SERVER['DOCUMENT_ROOT'] with a
> constant, DOC_ROOT. Now, the challenge is to define the constant.
>
> Suggestions?
>
> One important thing. The file the constant will be defined in is not
> necessarily going to be a file at the web root level.
>
> Thanks for all your help, - Dave
>


IMHO if they can't or won't fix $_SERVER['DOCUMENT_ROOT'], then it's
time to change hosting companies. I wouldn't host with a company who
screwed up such an important predefined value.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #8 (permalink)  
Old 06-28-2007
jussist@gmail.com
 
Posts: n/a
Default Re: Determining document root when $_SERVER['DOCUMENT_ROOT'] is not an option

Just do print_r($_SERVER); and find what is there. I bet you can find
the useful info from there.

Now I'm a little bit on same directions with Jerry. Why did they do
that? If they've blocked all useful information from SERVER -vars,
then get worried about their admin -skills. Perhaps... they don't want
users to know the paths, because there is no security between user
accounts. Just my first thought, I might be faaa a a r off.

--
Jussi

Deep abstraction kills strong typing.

http://disczero.com
http://naamio.net
http://hoffburger.com

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:01 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0