I have a simple home page that I want to use to learn how to use SSI to set up my nav bar on the top and right with, so it can be quickly and easily updated in the future. (Would like to eventually figure out how to use this to display my banners and videos as well.)

I found some information on google, but its from pretty far back. It did help me get the jist of the include code etc though.

But there were no examples I could find on how to set up a nav bar, and have it appear on all your html pages.

I also have the nav bar currently set up with certain CSS styles, can I maintain that same color and style setup etc while using the SSI to somehow show the content of the nav bar within or using those style settings?

I hope to learn how to do this well, and I am eager to learn for any who want to help me.

Thank you!

E

jerry62704

02-23-2009, 05:38 PM

I use PHP on the server for this.

SSI Server Link (http://www.w3schools.com/PHP/php_includes.asp)

fastwave

02-23-2009, 05:40 PM

Well once I start to use and learn PHP, I will probably do the same *smiles*

But for now I need to learn how to insert this into XHTML

BoldUlysses

02-23-2009, 05:40 PM

There are a number of ways to do it but a PHP include is probably your best bet as most servers have PHP and only Microsoft IIS can run ASP. If your preference is to use ASP instead, contact your hosting provider and see what servers they use (can probably find it in service documentation as well). Anyway.

With PHP, it's quite simple. Take the nav bar code and isolate it (no normal HTML body tags or DOCTYPE--just the nav markup) in its own PHP file:

Remove it from its original markup document and put this (or equivalent) in its place:

<?php include("navbar.php"); ?>

where navbar.php is the name of the file with the nav code. Resave your original markup document, now with the PHP include, with a .php file extension. Upload to server running PHP and voilą, SSI.

As far as your stylesheet is concerned, the browser parses the CSS code once the HTML file ("assembled" at the server by PHP) is delivered, so the browser "sees" exactly the same thing as if you didn't use the SSI at all--your stylesheets can remain the same.

Great tips guys thanks! Now if I do it that way excavator, do I need to change the main pages file extension to .shtml instead of the current html?

BoldUlysses

02-23-2009, 05:56 PM

If I may: You need to rename it with a .php file extension--this tells the server to process the file with PHP and not just relay it as static (X)HTML. You should also know that unless you have your local computer set up as a server running PHP, you won't be able to test the files until you upload them to your remote server. It makes testing a little more cumbersome, but the benefits of server-side processing far outweigh the inconvenience.

fastwave

02-23-2009, 05:57 PM

I am doing it all locally for now, will upload it once it tests out. Thanks for that Php extension tip msuffern, never messed with php myself.

fastwave

02-23-2009, 06:04 PM

I meant to say I am doing it all on my pc, will create files with test names, upload them to godaddy, then test them on their server, thanks for the tips.

You all rock!

Excavator

02-23-2009, 06:05 PM

Great tips guys thanks! Now if I do it that way excavator, do I need to change the main pages file extension to .shtml instead of the current html?

My sites that have php includes are still named with the .html extension. The included file itself is the only thing I've used the .php extension on.

BoldUlysses

02-23-2009, 06:09 PM

My sites that have php includes are still named with the .html extension. The included file itself is the only thing I've used the .php extension on.

Don't you mean the other way around? This file works when named, for example, phpcontainer1.php:

And when i got to the url for the html page, the spot where the php nav bar should be showing up is only showing my css style stuff like background color, the php file is in a subfolder under the main root folder called "includes" , which i included in the path info, please help me figure out what I am doing wrong

fastwave

02-23-2009, 06:52 PM

Anyone...please? :confused:

fastwave

02-23-2009, 06:58 PM

Ok got it, once i change both file extensions to php it worked, hehe thanks!

freedom_razor

02-24-2009, 12:41 PM

My sites that have php includes are still named with the .html extension. The included file itself is the only thing I've used the .php extension on.

That's possible if in your .htaccess [or httpd.conf] file you have something like:

AddType application/x-httpd-php .php .html

It will make a server parse all .html pages as .php. If there are a lot of pages though, that's a bit of work to do for a server [it will go through all .html pages looking for PHP in them], so IMHO, it isn't as good solution as just changing extensions to .php for pages that actually contain any PHP in them.

Excavator

02-24-2009, 08:44 PM

I do have a line - AddHandler application/x-httpd-php5 .php .html .htm - that makes the server look for php in an html document. It was added to my .htaccess by support @ my host way back when I was first setting up my included menu.

That explains why I'm telling the OP he does not have to rename his html document to get his include to load.

I just got an email back from my host asking about this. Here is their reply
The addhandler just tells the PHP binary to also parse any additional extenion types when the page is requested. It does not decrease/increase performance at all. I would leave it the way you are doing it now if you\'d like. Its just a matter of preference.

I'm considering changing it anyway, if only to stop me from giving bad advice again.