Jump to content

Suggestions on how to achieve my goal.


xn1

Recommended Posts

Hello all,

 

I'm looking for some advice on a problem.

I have a very basic web page containing three section, the header, the content and the footer in that order. What I would like is the header and footer always on the page and only the content section change by means of links in a navigation bar. I've looked into iframes, php include, javascript and something called Ajax and must say I'm all a bit confused by it all.

 

Which would be most advisable and how would I excecute it.

 

My pages are as follows.

Home page is.

index.php

Pages I would like to show in the content Div.

about.php

contact.php

home.php

 

If you need any more information, please let me know.

 

Thank you in advance for your help.

Link to comment
Share on other sites

In ASP.NET there is a concept called Masterpage where this can be solved easily. But in php, you have to break it up in this way: header.php, footer.php, left_section.php and right_section.php.

In your left_section.php keep the navigation bar.

Now in each page, include header.php, left_section.php and footer.php and in the right_section.php keep changing the content. I think this can best be tackled if you use a css style. There are many open source css style available in internet. A little bit goggling will come to your help.

Best of luck.

Link to comment
Share on other sites

Sanjib's suggestion makes sense until he starts talking about CSS files.  CSS has nothing to do with this.

 

PHP Includes are the way to go for this.  Make your header.php that prints out the titlebar, navigation, etc.  Make your footer.php that prints out the footer, copyright, and any necessary footer code like tracking pixels or whatever.

 

Then, every page on your site looks like this:

<?php

include("header.php");

//page contents

include("footer.php");

If you require a database connection, make it in header.php.  If you have functions that are required on every page, require them in header.php, etc.

 

Header and footer can also be page-aware.  The various $_SERVER variables like the request string and the page name are set by the user's REQUEST.  If they visit your "aboutUs.php", then the request URI will be "aboutUs.php" even inside header.php, so you can highlight the page they're on in the navigation menu and everything.

 

-Dan

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.