Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP - use includes for header, body and footer

Posted on 2014-09-19
6
Medium Priority
?
180 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:Aleks
  • 4
  • 2
6 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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:Aleks
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:Aleks
ID: 40332424
Never mind. I realized that wherever I place the code that is where the include is added  :)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Closing Comment

by:Aleks
ID: 40332427
Thanks !
0
 
LVL 111

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:Aleks
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

824 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