Forum Moderators: open

Message Too Old, No Replies

include code for HTML - differences from PHP includes

how do you include other pages i.e. header / footer in html

         

silverfish

1:21 pm on Feb 9, 2005 (gmt 0)

10+ Year Member



Does anyone know how to use the include command in a HTML file? I can make it work in php but the <!--#include file="filename"--> doesnt seem to work when i use it in HTML, any ideas?

lammert

2:00 pm on Feb 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have noticed that sometimes you have to add a space for the ending -->, so " --> instead of "-->. Another thing might be that your host does not parse SSI for normal HTML files. You could change the extension to .shtml, or add a few lines to your .htaccess file (if you are using an Apache webserver). I needed to add the following three lines to my .htaccess to get SSI working for .html files. I think for many hosts only the second line is enough because SSI is enabled for .shtml extensions on most hosts.

AddType text/html .shtml
AddHandler server-parsed .html
AddHandler server-parsed .shtml

Furthermore I use the virtual parameter instead of the file parameter, for example:

<!--#INCLUDE VIRTUAL="/filename.shtml" -->

andmunn

3:59 pm on Feb 9, 2005 (gmt 0)

10+ Year Member



Hello All,

I used to use "SSI Includes" all the time, but since using PHP for several programs, i have converted to using PHP includes.

Is there any advantage to using SSI as opposed to the "<php include=""> function?

Just curious.

Thanks,
Andrew.

PS - sorry to steal the thread!

lammert

4:28 pm on Feb 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The browser sees only the result of the include action, so from the user side there is no difference between the SSI and PHP include. One difference is, that SSI is parsed faster than PHP in most implementations - especially if PHP is a CGI addon and not directly compiled in the httpd server - so on a heavy loaded server you might see a slight performance increase, although this is hardly mentionable on todays fast processors.

You can even combine them. Most of my pages are in HTML, but I use PHP sometimes. With the line <!--#INCLUDE VIRTUAL="/file.php" --> the PHP file file.php is included and executed as PHP, although the calling file is a plain HTML file.

rocknbil

4:57 pm on Feb 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think for many hosts only the second line is enough because SSI is enabled for .shtml extensions on most hosts.

This is the first thing to verify - many servers explicity do not enable SSI for security reasons, so make sure your host has it enabled, and you **will** need to use the .shtml extension. This separates the files that require parsing from the files that don't, which decreases server load.

Secondly, use include file for same-directory includes and include virtual for includes from other directories.

And last, the space after the include command is indeed important.

lammert

5:13 pm on Feb 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you **will** need to use the .shtml extension

I agree that enabling SSI for plain HTML causes the SSI parser to be used for all files, including those not containing SSI statements. But the topic was about adding a header / footer to pages, which makes me think the include statement will be used in many, if not all HTML files.

Enabling SSI for .html files has a great advantage for existent sites which already have a decent ranking in Google and other search engines. You don't have to change the url and therefore you won't lose your current SERP position. There is also no need to set up a set of 301 redirects from .html to .shtml to preserve incomming links.

In general if you have to develop a new site, .shtml is the better choice, but when changing an existing site to have a common header and footer I would recommend .html. Impact on server performance is now not such an issue anymore as in the early days. Many .html files you see on the net are in fact .php files with a proper rewrite rule in Apache or IIS.

Rachna

11:39 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



But just curious to know ......where to include
<!--#include VIRTUAL="/filename.shtml" -->
in the HTML code.

lammert

5:40 am on Feb 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The <!--#INCLUDE --> statement is directly replaced by the content of the include file. You place the code where you otherwise would have entered the header or footer HTML tags.

This is different from the C/C++ language #include statement which is most of the time placed at the beginning of the file.