K
K
Kyrsorf2018-03-25 00:36:33
PHP
Kyrsorf, 2018-03-25 00:36:33

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

2 answer(s)
R
Rsa97, 2018-03-25
@Rsa97

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.

E
Ernest Faizullin, 2018-03-25
@erniesto77

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 question

Ask a Question

731 491 924 answers to any question