473,670 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

phpinfo() and $_SERVER['DOCUMENT_ROOT'] constant

I have just discovered that the value reported for
$_SERVER['DOCUMENT_ROOT'] by phpinfo is different from the value I
obtain when I run the following:

<?php echo $_SERVER['DOCUMENT_ROOT'] ?>

My natural assumption is to assume that this is a joke (like most of the
PHP language in my experience so far) - but seriously, does anyone know
why on earth a diagnostic tool like phpinfo() displays values that are
different from that obtained via a script call?

BTW - this is what explains my previous post - where I was wondering why
my require_once() was not working. I had blindly believed the values
spat out by phpinfo(0.

Its only under careful investigation, that I realized that the values
are different .. so I'm just going to "hack it", and simply hard code
the value, than believe anything phpinfo() has to say ... unless Im very
much mistaken ... can anyone explain this madness ?.
Jun 2 '08 #1
4 4130
On Mon, 12 May 2008 22:58:14 +0200, Ronald Raygun <in*****@domain .com>
wrote:
I have just discovered that the value reported for
$_SERVER['DOCUMENT_ROOT'] by phpinfo is different from the value I
obtain when I run the following:

<?php echo $_SERVER['DOCUMENT_ROOT'] ?>

My natural assumption is to assume that this is a joke (like most of the
PHP language in my experience so far) - but seriously, does anyone know
why on earth a diagnostic tool like phpinfo() displays values that are
different from that obtained via a script call?
Only it is called from another method/instance with another document root.
For a certain configured host in apache, it will always report the right
host, unless you yourself changed it. If you don't like working with PHP,
just don't work it. Don't knock it on the basis of your own errors. There
are certainly some faults with PHP, however nothing you mentioned is one
of them.
Its only under careful investigation, that I realized that the values
are different .. so I'm just going to "hack it", and simply hard code
the value, than believe anything phpinfo() has to say ... unless Im very
much mistaken ... can anyone explain this madness ?.
Most probable: it's a user reading error, check again.

Less probable: somewhere in the code, a wrong value is assigned to
$_SERVER, as it's sadly not read-only. The most likely case where this
could happen is within an IF statement actually assigning instead of
comparing.

Unprobable: different hosts configured with different roots, and not the
same context is checked against each other.

Very unprobable: a very weird specific PHP error, reinstall/recompile.
--
Rik Wasmus
[SPAM] Now temporarily looking for some smaller PHP/MySQL projects/work to
fund a self developed bigger project, mail me at rik at rwasmus.nl. [/SPAM]
Jun 2 '08 #2


Rik Wasmus wrote:

If you don't like working with PHP, just don't work it.

Ah, ... If life were that simple.
Jun 2 '08 #3
On 12 May, 22:28, Ronald Raygun <inva...@domain .comwrote:
Rik Wasmus wrote:

If you don't like working with PHP, just don't work it.

Ah, ... If life were that simple.
Life may not be that simple, but people sometimes are.
Jun 2 '08 #4
On Mon, 12 May 2008 23:28:05 +0200, Ronald Raygun <in*****@domain .com>
wrote:
Rik Wasmus wrote:

If you don't like working with PHP, just don't work it.

Ah, ... If life were that simple.
Ah, well, as long as you don't forget to read on in that post to the
possible scenario's & solutions mentioned.
--
Rik Wasmus
[SPAM] Now temporarily looking for some smaller PHP/MySQL projects/work to
fund a self developed bigger project, mail me at rik at rwasmus.nl. [/SPAM]
Jun 2 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9784
by: chops | last post by:
I need the path of the script that is running. Unfortunately it is not in the $_SERVER array when running a script through the CLI. Through a browser I can strip the script name off, e.g $_SERVER => "C:/Apache2/htdocs/test/filename.php" However through the CLI the path doesn't appear in $_SERVER. Only the script name. Actually $_SERVER, $_SERVER and
6
7783
by: olafmol | last post by:
Hello, on my windows NT4 server with IIS4 and PHP Version 4.3.1 i don't have any "DOCUMENT_ROOT" environment var. Is there any reason i dont get this? Can i do something about it? I need this because i run a template with an include inside an eval-block that is requested from 2 different locations. Thanks, Olaf
6
8461
by: Tom | last post by:
I'm trying to dynamically adjust the path for one of my scripts using this: $script_path = str_replace( $_SERVER, "", dirname(realpath(__FILE__)) ) . DIRECTORY_SEPARATOR; The problem: the server I'm currently testing it on returns for $_SERVER something like the path "home/user/path/" and for __FILE__ "home2/user/path/scriptdir/" I tried to trace the discrepancy running phpinfo, but the only reference I can find to
4
16122
by: Chris | last post by:
I'm working on a large intranet group site with a lot of pages, file types, folders, subfolders, etc. I am using the include ('../includes/file.php') , but I would like to have a single snippet that will work for all .php/.html pages in all subfolders. I have seen the $_SERVER indicated as a way to access the root of the website without using ../ for each folder you have to pass up through. However, I cannot get this to work for me. ...
4
2390
by: monomaniac21 | last post by:
Why does this find the file: <img src="<?=$_SERVER?>/images/viessmann_header_logo.gif"> But this does not? $right_content = $_SERVER."includes/content/content.php";
12
2330
by: comp.lang.php | last post by:
Env: Windows XP, Apache 1.33, PHP 5.2.0 <? echo is_dir($_SERVER) . " for dir = " . $_SERVER); ?>
6
3503
by: Jeff | last post by:
Is $_SERVER alway available? I ask this because I've seen on windows that the perl equivalent was missing. Is this settable and accessible the same way (ie not having to use global)? Jeff
0
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8810
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8590
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7410
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2798
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2035
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.