Solved

PHP - use includes for header, body and footer

Posted on 2014-09-19
6
169 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 108

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Closing Comment

by:amucinobluedot
ID: 40332427
Thanks !
0
 
LVL 108

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now