Solved

PHP - use includes for header, body and footer

Posted on 2014-09-19
6
176 Views
Last Modified: 2014-09-19
I am new to PHP and bootstrap, but I managed to create a page that has a top navigation bar, such as the one on this page (logo and nav bar), then the body and at the bottom the footer. But right now this "page1.php"  has all the code.
I am about to start doing many pages and I don't want to repeat this code on every page, I just want to add an 'include', so that when I do add that line of code then it calls the page and displays the top and bottom besides whatever code I have on the page.
What would the code be for that ?

"page1.php"  would be the body
"top.php" would be the header and navigation bar
"footer.php" would be the footer.

If I take the code out of 'page1.php' and put it into 'top.php' and 'footer.php' ... what code would I need to add to 'page1/php'  to call for the other two pages and for page1.php to know that they go at the top and bottom of the page.

I hope I explained myself properly.
0
Comment
Question by:amucinobluedot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40332332
You're thinking is on the right track.  Here is the general design I follow for PHP pages.

require_once('common.php'); // Session, Cookie Handler, Database Connectivity but NO BROWSER OUTPUT
require_once("top.php"); // would be the header and navigation bar
require_once("page1.php"); //  would be the body -- might be in clear text, not necessarily a require()
require_once("footer.php"); //  would be the footer. 

Open in new window

0
 

Author Comment

by:amucinobluedot
ID: 40332345
There was a problem tho ... the header is displayed properly at the top, but then the footer is displayed just under the header and before the body. How do I make the 'footer.php' be displayed AFTER the body ?
0
 

Author Comment

by:amucinobluedot
ID: 40332424
Never mind. I realized that wherever I place the code that is where the include is added  :)
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Closing Comment

by:amucinobluedot
ID: 40332427
Thanks !
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40332535
Yes, the code runs top-to-bottom unless control structures change the logic flow.  Thanks for the points and thanks for using E-E, ~Ray
0
 

Author Comment

by:amucinobluedot
ID: 40332540
Thank you !  I am just starting with PHP seems pretty straight forwards. I am also using some DW extensions for faster development, so far I have used it with bootstrap and looks great !  And you are welcome.
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question