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

Troubles with Enhancing a Simple PHP Application Challenge task 3 about relative server path.

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.

and I wrote this but it doesn't work and i dont know why.

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

<html>
<head>
 <title>Leadership | Shirts 4 Mike</title>
</head>
<body>

<h1>Leadership</h1>
<p><strong>Owner:</strong> ????</p>
<p><a href="/contact/">Contact</a></p>

</body>
</html>

this is link to a Challenge task (task 2)

http://teamtreehouse.com/library/enhancing-a-simple-php-application-2/cleaning-urls-with-subfolders/server-paths-and-constants

10 Answers

andi mitre
STAFF
andi mitre
Treehouse Guest Teacher

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

<html> <head> <title>Leadership | Shirts 4 Mike</title> </head> <body>

<h1>Leadership</h1>
<p><strong>Owner:</strong> ????</p>
<p><a href="/contact/">Contact</a></p>

</body> </html>

andi mitre
STAFF
andi mitre
Treehouse Guest Teacher

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

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

try removing the single quotes around $_SERVER["DOCUMENT_ROOT"]

I have tried but it doesn't work .

I already pass it thank you

what was the solution?

I'm not sure that's correct. $_SERVER["DOCUMENT_ROOT"] will give you document root, which is /htdocs/ after that you need to go into /config folder and that is done by . 'config/company.php');

The solution is :

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

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