Answer the question
In order to leave comments, you need to log in
DOCUMENT_ROOT in PHP 7+, how to fix error?
Warning: Use of undefined constant DOCUMENT_ROOT - assumed 'DOCUMENT_ROOT' (this will throw an Error in a future version of PHP) in
$fp = fopen($_SERVER[DOCUMENT_ROOT].'
The question is how to fix it without writing the full path.
Answer the question
In order to leave comments, you need to log in
Actually, this warning will be in PHP 5 as well. The DOCUMENT_ROOT constant is not defined, so PHP assumed it needed the string 'DOCUMENT_ROOT'. To avoid a warning, add quotes.
somewhere at the top of the index.php file must be added
in this way, I fixed the error for myself
you can protect yourself even more
if (isset($_SERVER['DOCUMENT_ROOT']))
define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']);
else
define('DOCUMENT_ROOT', null);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question