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

Paul Braden
PLUS
Paul Braden
Courses Plus Student 6,734 Points

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

John Breiner
John Breiner
6,918 Points

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

J.T. Gralka
J.T. Gralka
20,126 Points

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

Coco Jackowski
Coco Jackowski
12,914 Points

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?

Coco Jackowski
Coco Jackowski
12,914 Points

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?

John Breiner
John Breiner
6,918 Points

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

Paul Braden
Paul Braden
Courses Plus Student 6,734 Points

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

John Breiner
John Breiner
6,918 Points

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.

Paul Braden
Paul Braden
Courses Plus Student 6,734 Points

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

John Breiner
John Breiner
6,918 Points

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