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

[email protected] (Ashley Sheridan)
Newsgroups php.general
Message-ID <[email protected]>
On 13/09/2021 20:14, Bo Berglund wrote:
> I have a website that was created years ago with PHP handlers for database
> access etc. After upgrading the webhotel PHP version to 7.0 from 5.3 the site
> functionality broke!
>
> The main php file store is in htdocs/php but there are other places where these
> files are referred to as includes using this syntax:
>
> include ($_SERVER["DOCUMENT_ROOT"] . '/php/appdbdata.php');
>
> And these includes are used in many places at different folder depths in the
> site.
> But now the only way I have found to handle this is to use relative paths and it
> does not work well for files that are moved between directories.
>
> QUESTION:
> ---------
> What can I use in PHP 7 in order to include php files relative to document root?
>
> I have tried googling but I always get to hardcodes solutions which is not good
> when files are in different directories.
>
> For the php files residing inside /php I simply replaced the construct with
> (example):
>
> include_once ('appdbdata.php');
>
> THen seemingly all worked, but only until a call was made to a php file at a
> deeper location which also included this file...
>
Have you looked at __DIR__ ? 
https://www.php.net/manual/en/language.constants.magic.php

-- 
Ashley Sheridan
https://www.ashleysheridan.co.uk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.