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 trialTobias Kocks
9,018 PointsBroken code challenge?
Hey everyone,
The “Server Paths and Constants” code challenge is really killing me. I'm usually really hesitant to assume that the error source is not with me, but somewhere else. But in this code challenge I really can't see what I would be doing wrong. Moreover, some variables and output are behaving strange.
Here's the problem. It started with challenge 2/3, where we're asked to include the company.php file located in the htdocs/config subfolder. Since the workspace indicates that we're editing an index.php file in the htdocs/about/leadership directory, I'd say we'd have to go up two directories and from there navigate to the config folder. Hence my solution
<?php include("../../config/company.php"); ?>
However, this gives me a Bummer error. I really don't see how this would be wrong. Moreover, if I print the variable $_SERVER["DOCUMENT_ROOT"] it returns an empty string. If I preview the result under the above include method, I get the following error output:
PHP Warning: include(../../config/company.php): failed to open stream: No such file or directory in about/leadership/index.php on line 2 PHP Warning: include(): Failed opening '../../config/company.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in about/leadership/index.php on line 2 Leadership Owner: ???? Contact PHP Notice: Undefined variable: NiIxjVEFyf7i6Mty in 8abd1f07-eac1-4f3c-a91e-9350fb941520.php on line 76
What is even more weird, if I just leave out the upward navigating operators, and just write the include statement like this
<?php include("config/company.php"); ?>
which would imply that the company.php file is in the same folder as the about/leadership/index.php (which in the exercise was stressed not to be the case) the challenge tells me that my code is correct and I may proceed with step 3.
In the third step, I again get an error telling me that the $owner variable would be present, but that something with the html would not be okay. I don't see what it could be. I left the old html intact and only substituted the question marks with the echo statement, taking account of the extra space character being printed between the colon and the name. If I preview the output, it seems to look just fine. However, the challenge wont let me pass.
This is really frustrating. I've been spending hours, not progressing any further because of this.
Greetings.. Tobias
<?php
include("config/company.php"); //This works for code challenge 2/3, though I think it should be --> include("../../config/company.php");
echo "Root directory is: " . $_SERVER["DOCUMENT_ROOT"]; //Only prints "Root directory is: "
?>
<html>
<head>
<title>Leadership | Shirts 4 Mike</title>
</head>
<body>
<h1>Leadership</h1>
<p><strong>Owner:</strong> <?php echo " " . $owner ?></p>
<p><a href="/contact/">Contact</a></p>
</body>
</html>
Tobias Kocks
9,018 PointsYeah, just figured it some time after I posted my problem. Thanks for your help!
1 Answer
Ted Sumner
Courses Plus Student 17,967 PointsI ran into the same problem on this code challenge and posted about it.
Jeff Lemay
14,268 PointsJeff Lemay
14,268 PointsThat is a little strange about the config.php path.
But to get to your barrier... You have echoed a space before the owner's name, but there is also a space before your opening php tag. So you in fact have two spaces before the owners name is printed. Remove the one inside the echo statement.