boat73 has asked for the wisdom of the Perl Monks concerning the following question:

Hello wise ones, I have enabled my Apache server to use SSI with .shtml extensions and it works fine if I create ssi.html with the following code.
<html> <head> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=windows-12 +52"> <title>New Page 1</title> </head> <body> <!--#echo var="DATE_LOCAL" --> </body> </html>
What I want to do is to print the shtml in a cgi program but this code does not work. Could someone point me in the right direction please? Here is my cgi code:
#!c:/Perl/bin/Perl.exe use CGI; use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/shtml\n\n"; &printtest(); sub printtest{ print <<ENDHTML <html> <head> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=windows-12 +52"> <title>New Page 1</title> </head> <body> <!--#echo var="DATE_LOCAL" --> </body> </html> ENDHTML }

Replies are listed 'Best First'.
Re: Server Side Includes with print <<ENDHTML
by skx (Parson) on Nov 22, 2004 at 15:45 UTC

    When you enable SSI for Apache you do so by associating a MIME type, or a file suffix, with the include module. You do this by making the SSI handler 'server-parsed' be called to handle all requests of the given type.

    A common configuration is the following:

    AddHandler server-parsed .html Options +Includes

    When you setup Apache to execute CGI script you associate the relevent directory, or file suffix (.cgi?) with the CGI handler in a similar manner.

    Apache will only run one handler for a given file, and it will be whichever one is setup for that MIME type or suffix.

    So you have the choiec - either do the thing as a CGI script by calling your script foo.cgi or write the whole thing as a SSI document and call your script foo.shtml.

    The latter approach might be the way for you to go, after all using SSIs you can include the output of an arbitary URL (read CGi script) into your page.

    Apache2 allows you to chain handlers together to do what you want, but Apache 1.3.x doesnt.

    Steve
    ---
    steve.org.uk
Re: Server Side Includes with print <<ENDHTML
by ikegami (Patriarch) on Nov 22, 2004 at 15:39 UTC
    That's a server configuration issue, something with which I am not familiar. I do have a comment to offer, however. Be very careful when enabling SSI on the output of CGI scripts (or other dynamic content). CGI scripts often output text submitted by remote users. Make sure that any text submitted by a user is filtered of any SSI to prevent undesired "side-effects".
Re: Server Side Includes with print <<ENDHTML
by Mutant (Priest) on Nov 22, 2004 at 16:29 UTC

    Unless you *really* need SSI's, you may want to consider getting the functionality of SSI from Perl. Pretty much all of SSI's functionality (well, as much as I can remember, it's been years since I've used them) can be duplicated by Perl. Most of what you need is probably in HTML::Template (ie. this will allow you to include files, so you can have your layout in separate files, and won't have to update every file when you make layout changes.)

    SSI's can be useful if you don't have full control of the server, and your admin won't let you install much, but it sounds like you have access to your server, so you can install stuff off CPAN.

Re: Server Side Includes with print <<ENDHTML
by perrin (Chancellor) on Nov 22, 2004 at 17:00 UTC
    You can do that with apache 2, but not with apache 1. With apache 1, you need to use something like CGI::SSI_Parser.
      I am running apache2, I would greatly appreciate an example. Thanks
        <Location /cgi-bin> SetOutputFilter INCLUDES </Location>
        See the mod_include documentation for more.