1

After an PHP upgrade from 5.2 to 5.5 (or newer) a friend's web site is not working anymore, regarding the host identifier ($DOCUMENT_ROOT).

He is using this code:

<?php
require("$DOCUMENT_ROOT/menulinks.inc.php");    
$status = $menu["home"]["id"];
require("$DOCUMENT_ROOT/header.inc.php");
?>
<div id="main">
<img src="images/miristart.jpg" alt="Startbild" style="margin-top 2%;"/>    
</div>
<?php 
require("$DOCUMENT_ROOT/footer.inc.php");
?>

And that is the error code:

Warning: require(/menulinks.inc.php): failed to open stream: No such file or directory in /www/htdocs/v137122/sedcard.php on line 2

Fatal error: require(): Failed opening required '/menulinks.inc.php' (include_path='.:/usr/share/php:..') in /www/htdocs/v137122/sedcard.php on line 2

So, do I have to use another command instead of $DOCUMENT_ROOT? Which one then? Thank you very much in advance.

vega
  • 127
  • 3
  • 12
  • You could check out the answers to this similar question:http://stackoverflow.com/questions/11927968/document-root-php – Mike Feb 22 '17 at 18:54
  • Possible duplicate of [Document Root PHP](http://stackoverflow.com/questions/11927968/document-root-php) – xkcd149 Feb 22 '17 at 19:03

1 Answers1

1

First $DOCUMENT_ROOT is a variable.

During the update the PHP option register_globals was set to off. You can still access the document root through the $_SERVER array. This will look like $_SERVER ['DOCUMENT_ROOT'].

Kyoya
  • 343
  • 2
  • 5
  • I changed require("$DOCUMENT_ROOT/menulinks.inc.php"); to require("$_SERVER['DOCUMENT_ROOT']/menulinks.inc.php");, but that did not work at all. – vega Feb 23 '17 at 14:17
  • Your code `"$_SERVER['DOCUMENT_ROOT']/menulinks.inc.php"` will resolve to `"Array['DOCUMENT_ROOT']/menulinks.inc.php"`You need to add curly braces: `"{$_SERVER['DOCUMENT_ROOT']}/menulinks.inc.php"` – Kyoya Feb 23 '17 at 17:41
  • {$_SERVER['DOCUMENT_ROOT']} did the job, thank you very much. :) – vega Jun 26 '17 at 15:58