Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDavid Wall
11,088 PointsROOT_PATH not working.
I can't include the header.php or footer.php using ROOT_PATH.
My config.php file is as follows(it's in the inc folder at the root):
<?php
define("BASE_URL", "/");
define("ROOT_PATH", $_SERVER["DOCUMENT_ROOT" . "/"]);
My index.php file is as follows(it's in the receipt folder at the root):
<?php
include_once("../config.php");
$pageTitle = "Thank you for your order!";
$section = "none";
include(ROOT_PATH . "inc/header.php");
?>
6 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi David,
I don't think you have the correct relative path to your config file.
If your index file is in the "receipt" folder then you would need to go up one level then down into the "inc" folder.
include_once("../inc/config.php");
Try making that change as well as the one Chris pointed out and let us know what happened.
Jeremy Hayden
1,740 PointsTry echoing out your root path to see if its working
Chris Shaw
26,676 PointsHi David,
You have a syntax error in your constant which needs to be resolved, currently you have the below which if you look closely you have concatenated your path onto the key name DOCUMENT_ROOT
which should be on the other side of the closing square bracket.
define("ROOT_PATH", $_SERVER["DOCUMENT_ROOT" . "/"]);
Should be:
define("ROOT_PATH", $_SERVER["DOCUMENT_ROOT"] . "/");
Happy coding.
David Wall
11,088 PointsThanks for the replies. Thanks Chris. Sorry, i did have it that way before. I've redone this part so many times. It still doesn't work. Jeremy, i ran this:
<?php
include_once("../config.php"); echo ROOT_PATH; $pageTitle = "Thank you for your order!"; $section = "none"; include(ROOT_PATH . "/inc/header.php"); ?>
with this in the config:
<?php
define("BASE_URL", "/"); define("ROOT_PATH", $_SERVER["DOCUMENT_ROOT"] . "/");
The result is the words "ROOT_PATH" being echoed, not the actual path. So the ROOT_PATH isn't actually being defined...right?
Jeremy Hayden
1,740 PointsJust to check off the possibility that your config file does not have any errors, and is actually loading into main file, put a test echo at the end of it.
In fact, i would put 2 echos, a simple test, and the rootpath.
David Wall
11,088 PointsThanks Jason. That's definitely it!