Search code examples
phpinclude

Why do my php includes return, "failed to open stream: No such file or directory in..."


I'm using simple include files for common elements on a mostly static website. I do so like this

<?php include('/inc/header.php'); ?>

But this doesn't work unless i remove the leading slash, and then it only works on pages in the root directory. What am I doing wrong?


Solution

  • '/' means the real server root directory.

    If you need web document root use :

     include("{$_SERVER['DOCUMENT_ROOT']}/inc/header.php");