i receive this PHP Error whenever i try to include a php file in my index.php:
No such file or directory
At first i include this file at the beginning of the index.php: require_once("../resources/engine/settings.php");
And i get no error, but when i include the header file with require_once($TEMPLATES."/header.php");
I get that error.
$TEMPLATES is a variable that’s declared in settings.php (that is included correctly into index.php).
This is settings.php:
<?php
$BASEURL = "http://localhost/webname";
$CSSFolder = $BASEURL."/public/css";
$CSS = $CSSFolder."/style.css";
$IMGFolder = $BASEURL."/public/img";
$ROOT = $_SERVER["DOCUMENT_ROOT"]."/webname";
$TEMPLATES = $ROOT."/resources/templates";
$ENGINE = $ROOT."/resources/engine";
?>
Instead of using
$_SERVER['DOCUMENT_ROOT'], i always use dirname to get the root path defined, and id suggest you to use that also. If you use this all over the place, you’ll faster get rid of all the path traversing confusion that can arise with it.I find it easier to work with, like this
Although they seem to return the same, using
DOCUMENT_ROOTreturns the absolute path of where the script is executing, whereas thedirnamecall is absolute to where the file is located physically.Now to address your question:
An easy way to debug includes like this is to actually just print out the path, which would be
print $TEMPLATES."/header.php"and check whether that is what you expect it to be, if not, then correct it.