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 trial

PHP Enhancing a Simple PHP Application Cleaning URLs with Subfolders Server Paths and Constants

Shen JIE LIN
Shen JIE LIN
10,612 Points

Challenge on Cleaning URLs with Subfolders

Question: There is a file located at htdocs/config/company.php on the server. We need to include that file to get access to some of information about the company. At the very top of the file below, before any of the HTML, include that company.php file using a relative server path.

My Answer <?php require_once($_SERVER["DOCUMENT_ROOT"] . "/config/company.php"); ?>

Please help

I have also tried

<?php include($_SERVER["DOCUMENT_ROOT"] . "/config/company.php"); ?>

4 Answers

Shen:

<?php require_once($_SERVER["DOCUMENT_ROOT"] . "../../config/company.php"); ?>

<?php require_once($_SERVER["DOCUMENT_ROOT"] . "../../config/company.php"); ?>

i cant get thru

This is the code that I used:

<?php include($_SERVER_ROOT . "config/company.php" ); ?>

Although, I just noticed, $_SERVER_ROOT is never mentioned in the video. In the video, they use $_SERVER["DOCUMENT_ROOT"], so I don't know if my solution is actually correct, or if I just found a loop-hole ^^:

Jimmy Maurice
Jimmy Maurice
9,379 Points

@William J.Terrell, your solution is correct but i don't understand why.. Like you said, it was never mentioned in the video. What is the difference with $_SERVER["DOCUMENT_ROOT"] For me there is a bug somewhere. It is illogical. Anyway thanks for the solution !