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 144,865 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
9,677 Points

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

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!

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.

nice videos..