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 Build a Simple PHP Application Creating the Menu and Footer Including the Header

I keep getting this php error. Please help I can't seem to figure it out

Warning: include(inc/header.php): failed to open stream: No such file or directory in C:\xampp\htdocs\index.php on line 28

10 Answers

The inc folder is in the same folder as index? If index is in public and inc is on the same directory level as public, make sure to have ../inc/header.php

Hey Paul Braden,

As Cole Jackowski pointed out, it might have something to do with the web server you're running on your local machine. Depending on how you have your server configured, you might need to use backslashes (\) instead of forward slashes ('/') in your paths.

It's a pain in the rear, sometimes working between platforms, so it might help to check out the DIRECTORY_SEPARATOR constant in the php documentation on Predefined Constants.

Best,

J.T. Gralka

This means that the file you tried to include() wasn't found. Perhaps because you didn't put the filename string in quotes? Could depend on your system and configuration. Can you post a more full code snippet?

no they are in quotes

A quick look at http://www.php.net/manual/en/function.include.php shows include used without parentheses, as in include 'file.php';. Have you run it that way? Again, a code snippet might help.

Do you have an 'inc' folder with 'header.php' in it?

<?php include("inc/header.php"); ?>

In other words its saying you aren't pointing directly to it.

Ok that was it but now I have two footers and two headers

Do you have the include for the header and footer in there more than once? Do you have the code from the include file also in your index file as well? If not it shouldn't be happening.

Yeah all those things are good to go I don't get it.

Without seeing all of it, that's what I can think of. Try <?php include once(); ?> instead of just the include