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

Issue with including header.php

your video example cuts and past the code from index.php and paste into a new file header.php within a new folder '/inc' but none of the links for the css file path is updated! so how is <link rel="stylesheet" href="css/style.css" type="text/css"> going to work when its now one level down from the index.php. The video says and there should be no change when we update the broswer! Wrong yes there is, the index.php as no formatting so appears completely different to that of the video.

Are we supposed to have set up the sever configuration differently to accept some relative back linking (even if thats possible). Its fundamentally important at this early stage when laying the foundation, that we get it write every time, or it has an impact on our confidence when its wrong and its not our fault.

18 Answers

After several attempts... <link rel="stylesheet" href="css/style.css" type="text/css"> the above line needs to be change <link rel="stylesheet" href="./css/style.css" type="text/css">

Small change './' , but if you don't know this and its your first time and you don't feel confident to try loads of edits until it works, then your stump!

Can you get back to me on how to get some feedback on this kinda mistake when you need it most, do you have staff around 24/7 as this is a global site so different time zones? Is their append-um of errors your aware of in your video's but corrected in your transcripts?

Eric

eric barns thanks for bringing up this issue. I'm not a moderator or Staff but I would assume that if you provide the video / lesson you're on it would help them navigate on what to help you with. It's hard to assume where you are at and what you are talking about when you leave out the juicy details that they and the forum community needs.

It seems like you solved the problem. One recommendation I would make is to download the source files to see how they have it when comparing to your code if something didn't make sense.

Hope this helps.

Justin Thanks, but where i am, is the video part is called 'including the header' in php lessons, thats the subject name of the topic of my discussion, i dont know how else to reference it, do they have a number system or other ordered list for naming (chapters, page, frame) i should look out for as and when this happens again.

By the way any clues on the support schedule, is it 24/7 or just Monday / Friday 9-5, need to know when i can plan my studies so their is support to help in these show stopping occurrences. Lucky i was able to after an hour, get passed their mistake, but that's not ideal.

You mean download the source file from the lesson that proceeds the one your on, as the build is sequential. Once again thanks for the response Eric

Just copy and paste the link for the relevant video, code challenge or quiz. Then we'll know what you're on about in detail.

I passed all those badges and don't recall such a problem.

Support is the forum, it's US based so can take time to get answers, if anyone has them. Search box is your friend. I've used it a tonne with the interactive website island before I gave up on the island.

If you're having issues with this video, I'd avoid interactive website island as it's hugely frustrating.

There's quite a few people who have voiced their frustrations so I expect it will be tweaked/redone in the near future.

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Hey Eric,

As far as I know, the video is correct. You shouldn't have to change anything in the header.php code. You moved the header.php file down a level, but it gets included back up a level in index.php; the exact same HTML gets sent down to the browser.

You didn't move the index.php file down a level, did you? That was supposed to stay in the root.

Does that help? ~randy

Hey Randy Hoyt

'Small change './' , but if you don't know this and its your first time and you don't feel confident to try loads of edits until it works, then your stump!' previous comment and this worked, so how comes it fixed it if wasn't broken?

I guess your point is the url is relative to the page running where the link is requested from (as an include in index.php it adopts this path, the parent path) not where the header.php is loaded from ?

But that's its academic (interested in the answer) in this situ as the amended code change was required.

Thanks for your response Eric

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

No, you shouldn't have to add "./" there. The following two lines of code are identical:

<link rel="stylesheet" href="css/style.css" type="text/css">
<link rel="stylesheet" href="./css/style.css" type="text/css">

These both mean the exact same thing: "Look in the current directory for a directory named css and then look for a file named style.css inside that directory."

There must be something else going on. Are you using MAMP or XAMPP? When you look at the page in your browser, is the web address you are looking at [http://localhost/]?

Randy, i am MAMP, downloaded clean as instructed and i down loaded your folders and copied into my host directory and the index.php worked and then lost all forms of styling when i made the changes for header.php and added it to inc folder.

The file is there Randy, as i said it works now but only with the amendment, is there a MAMP configuration to the apache files to allow ./ non ./ to work in the same fashion. From a computer science view, if this was desktop file browser, the difference would be very important.

its [127.0.0.1:8080/shirts4mike/]

Thanks for your support, Eric Barns

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

I think you might be confusing ../ with ./. The first means "look one directory above the current directory," but the second one means `look in the current directory'. These two commands would be identical:

$ cd css/
$ cd ./css/

Go to [127.0.0.1:8080/shirts4mike/] when it works, view the source code, copy the source code, and paste it in here? Looking at that might help me figure out what's going on.

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Eric,

I apologize that there still seems to be some confusion. You should not have to change the code after you copy and paste it. It should work just like it is:

<link rel="stylesheet" href="css/style.css" type="text/css">

I have no idea why that's not working for you; you should not have to add anything like ./ to it.

Would you mind sending me a screenshot or code of how you have it right now? You don't need to try to re-create the problem from the past. Could you load up the page [127.0.0.1:8080/shirts4mike/] with your amendment, view the source, and then send me a screenshot or a copy of the source code?

Randy,

To be clear, you want the code for header.php (this is where the amendment has been made) then send you screen grabs of the view source code via the email you sent me?

Eric

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

No, I want you to go to [127.0.0.1:8080/shirts4mike/] in your browser and view the source code there. Send me the screenshot of that source code. Does that make sense?

ok, sent it via email, markdown did'nt work for me needs an absolute parh?

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Can you try removing the ./ from that line, putting it back to this?

<link rel="stylesheet" href="css/style.css" type="text/css">

I'm almost certain that will work now.

Let me know!

alt text

Randy

Your right its working, so now i have no idea why, i am 99.9% sure i checked for typo's after all i did try several attempts for about an hour.

Thanks for your patients and look forward to continuing your excellent course unabated.

Regards Eric

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Excellent! Glad it's working for you. :~)