View Full Version : SSI include tags?

11-22-2003, 05:25 PM
The whole <!--#include file="something.html" --> doesn't seem to work on my page on westhost.. (comes up as a white box)

Is there something odd I have to take into account? It didn't work on 50megs either, they had a weird custom code for it..

I'll go doc hunting, see if i can find out before anyone replies. :) thanks in advance though..

Only refereces ive seen said Apache is already set up to parse html.. Hmm. :/

11-22-2003, 06:11 PM
It used to be that a SSI had to be ext shtml. Give that a try. I use it on several of my sites. If you need it to be an html ext you can use a .htaccess file in the directory you are trying this. I belive the correct syntext is

AddType text/html .html

11-22-2003, 06:50 PM
Thanks.. I tried renaming it .shtml (and including that instead), no luck.. I tried adding

Options +Includes
AddType text/html .shtml
AddHandler server-parsed .shtml

to the .htaccess and still nothing. Hmm.. I think I might go cheap on it and just use an IFRAME instead.. But I'd really rather not.. that's a last resort I guess..

11-22-2003, 08:15 PM
Have you looked in your /ect/httpd/conf/httpd.conf file to see if it is letting you overide with .htaccess in a directory? It should be enabled. You should see both of these in it. They are in diffrent areas but pretty well marked.

<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy All

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

Ahh.... Guess what I just noticed. :) Try this instead to call it.

<!--#include virtual="something.html" -->

You need to use virtual instead of file. You can also use the below if you want to call a .cgi or .pl from your cgi-bin

<!--#exec cgi="somescriptname" -->

NOTE: Make sure to use the correct path to the page you are calling.

I will leave the rest just incase you need to look in to those also.

11-23-2003, 05:35 AM
<!--#include file="thefile.txt"-->

works for me, and so does:

<!--#include virtual="thefile.txt"-->

I did not have to mess around with .htaccess or Apache config. All I did was put that line in a file with a .shtml extension, and it worked. I did note, however, it was picky about spaces between the <!-- and the #include... so I removed all unnecessary spaces.

Hmm... If I point it to a file that does not exist (or an incorrect path), it doesn't stay blank - it gives me:

[an error occurred while processing this directive]

What that tells me is that either your include statement is incorrect (excessive spaces?) and isn't even being "executed", or that your something.html is blank.

11-23-2003, 10:28 AM
Did some testing and Fayez is correct it should not matter if yu use file or virtual. If it can not find the file it should give you the error. Have you got it working yet? Also are you on WestHost 1.0 or 2.0? I belive that is where I got the virtual versus file thing. It seems it was mentioned in the old manual. Checked the version for for 1.0 now and it does not seem to mention it aside from haveing to use shtml ext.

11-23-2003, 10:49 AM
Sorry I took so long to reply!

I feel like a bit of an idiot now becase I completely FORGOT that my entire site was working through an SSI already! lol.. So I'm really sorry for wasting your time on that part.. :/ I'm on WH 2..

The question I now have to ask though is.. Can an SSI work inside *another* SSI..

And also, can an SSI work inside page which is actually dynamically generated by a PHP file? Specifically one which is also in an SSI? (the include tag being part of the header that's being parsed into the layout) Doh.. LOL, that sounds crazy, but there is reasoning behind it. :)

There was me thinking it was something simple and WH related, but I was just being blind to the fact I'm actually trying to do something a bit fiddly and mad.. I've been meaning to make my page statically generated for ages anyway, so this'll give me a good excuse to work on that. Whether I can get an SSI to work inside an SSI or not too, I'll report back with that, although people probably already know.

Sorry again, pretty inexcusable on my part.

11-23-2003, 02:19 PM
No problem at all! I allows us all to learn. :) I have not been able to get ssi to work in a PHP file but then that may be related to the
AddHandler server-parsed .shtml .html .htm .sht now that I think of it. I really did not dig into it since it was a passing fancy. Never tried an SSI inside an SSI so not sure on that one.

11-23-2003, 04:45 PM
Is there any reason you specifically want to use SSI to include files? I mean the PHP version is just as simple (see the manual - the function is include() or include_once()). You can definitely do "nested includes" in PHP - not sure about SSI, but I don't see why not. You could always SSI include a PHP or other dynamic page which in turn has includes in it (in the language specified, not SSI includes). Personally I think you should stick to one form of include (e.g. PHP) and avoid nested includes because it can get unnecessarily complicated. Depends on what it is you want to do, I suppose :)

11-24-2003, 01:35 PM
I think if you want SSI to work from a file generated by PHP you would have to try adding PHP to the server-parsed Handler. Meaning PHP will have two handlers in Apache and I'm not even sure if that will work.

But like Fayez says, if you can work it out so that the site just uses PHP, life will be a *whole* lot simpler... 8)