Solved

PHP - use includes for header, body and footer

Posted on 2014-09-19
6
173 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
  • 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp web application 3 35
Can't get js code to execute 8 30
PHP Underscores vs. Directory separators 5 26
Modify Filter to cause a field to be not Required 3 26
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

685 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