Solved

PHP - use includes for header, body and footer

Posted on 2014-09-19
6
168 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

705 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

12 Experts available now in Live!

Get 1:1 Help Now