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 Basic PHP Website (2018) Building a Media Library in PHP Including the Header

What is the advantage of including the Opening <DIV> command in the header file, rather than leaving it in the HTML file

In the last video I watched, the tutor created an INCLUDE file called header.php. This was created by copying all the header information from the basic HTML page, but she ALSO copied the opening <DIV> command of the 'main' HTML section of the page. Why?

Also, the same header.php file was used in a new file which (as far as I could see) did not have a corresponding closing </DIV> command, but no error was shown. Why??

4 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,857 Points

Hey Alastair,

She included the opening <div> because the tag will be common in all the pages the header is used (included) in. The closing tag for that div is actually in footer code, which is included in all the pages the header file is included in.

So, it opens in the header file and closes in the footer file. If you didn't include the footer file, you would encounter an error, yes.

Hope that makes sense. Keep coding! :)

Jonah Shi
Jonah Shi
10,140 Points

But we did not include footer.php at this stage yet? Even though, Suggest page still works for me?

Muhammad Athar
Muhammad Athar
4,004 Points

First time learning about includes. Does feel kinda awkward putting an opening tag in a separate file. Had to stop the video and come here to look why. I guess it'll take time to make it a habit.

Ah! That makes sense now. Thanks very much! I do use html includes myself but have always left the 'content' of the page intact so that it would remain useful on a standalone basis even if something went wrong with the includes or links to them. Irrational fear, I guess!

nice videos..