From the course: PHP for Web Designers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Moving common elements to include files

Solution: Moving common elements to include files - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

Solution: Moving common elements to include files

The challenge was to examine an existing website and to move common elements to server side includes. There's no single correct answer, but this is my solution using the Hansel and Petal site. I think it becomes fairly obvious, if you click through various pages, that there are common elements here at the top. The header, and the navigation menu. If we move down to the bottom of the page. there's this fat footer. Say, if I click arrangements, go down to the bottom, that same footer is there. So we've got three candidates for moving to server side includes, so let's get to work. I've got open in my editor, index.php, that's the home page. And, at the top, beginning on line 12, is the div with the id of header. And if I select that, there is my entire header. Immediately after that is another div with the id of nav_main, and if I select that. There is the entire navigation menu. Now I could put those into two separate include files, but because they come one after other, I think it is…

Contents