Re: How can I replace $_SERVER["DOCUMENT_ROOT"] in PHP 7.0?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 14/09/2021 11:09, Bo Berglund wrote:
On Tue, 14 Sep 2021 09:30:48 +0100, Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx>
wrote:

1. curdir: /data/25/2/158/91/2484743/user/2721122/htdocs/log
2. docroot: /usr/services/vux/apache/htdocs

Notice the vast difference between __DIR__ and $_SERVER['DOCUMENT_ROOT']!
They are not even close!
They're not meant to be the same, I suggested using __DIR__ as you said
you had problems with $_SERVER['DOCUMENT_ROOT'], suggesting it was not set
$_SERVER['DOCUMENT_ROOT'] seems to be set to:
  /usr/services/vux/apache/htdocs
which is an invalid path on the server (run by Network Solutions)

The path reported by __DIR__ is:
  /data/25/2/158/91/2484743/user/2721122/htdocs
and if I use this in an include statement it works just fine.

I have tested a lot of approaches and have concluded that this will in fact work
from *any* subdirectory on the website even very deep:

<?php
$rootdir= substr(__DIR__, 0, strpos( __DIR__, 'htdocs')) . 'htdocs';
include ($rootdir . '/php/logindata.php');
echo "Mail sender: " . $mailsender ;
?>

The result when executing it from a newly created directory several levels below
htdocs is:
Mail sender: donald@xxxxxxxx


* $_SERVER['DOCUMENT_ROOT'] should not be changing across scripts in a
website, suggesting the problem might be that it's not set to what you
think it is
It is not changing but it is set to an erroneous path.
I am not setting it, this is what PHP 7 supplies...

* Confirm $_SERVER['DOCUMENT_ROOT'] is exactly what you think it should
be across both versions
It worked fine in PHP 5.3 on Network Solutions webhosting, but when I allowed an
upgrade to PHP 7 on the site it was no longer working correctly...

If you go through the basic steps, you should see what the problem is.
I do not know what "basic steps" you are referring to but I think I have
outlined various tests I have done all giving the same result, i.e. if you are
in the document root and use __DIR__ then you get one result (the correct one)
but if you use $_SERVER['DOCUMENT_ROOT'] then you get a completely different
(and erroneous) result. The latter worked fine with PHP 5.3, has been running
for many years (about 8) without problems.

These problems only surfaced with the update to PHP 7.0.33 a week ago.

Maybe Network Solutions screwed up with their config of PHP 7?

The basic steps would have been just checking what $_SERVER['DOCUMENT_ROOT'] contained. That would have negated pretty much all the rest of the test code, etc, that you wrote, as that's the actual problem.

--
Ashley Sheridan
https://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux