Google Answers Logo
View Question
 
Q: cgi pulls html doc with a ssi - ssi doesn't work ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: cgi pulls html doc with a ssi - ssi doesn't work
Category: Computers > Programming
Asked by: horseradish-ga
List Price: $4.00
Posted: 16 Sep 2003 16:16 PDT
Expires: 16 Oct 2003 16:16 PDT
Question ID: 257445
I'm using cgi to pull an html doc into a page template.
I'd like to use a ssi in the html doc that's being pulled in as well.
The ssi works fine, pulled into the html doc when the html doc is
viewed directly.
But when I try to pull the html doc in via the cgi, with
www.mysite.com/cgi/template.cgi?content=htmldoc, the html doc does not
bring in the ssi. In fact when I look in the source code of the
resulting page, the #include file line is still there.

The template.cgi is in the cgi directory.
The htmldoc it pulls is in a top level folder called new.
The ssi .txt file is also in the top level folder called new.

Request for Question Clarification by serenata-ga on 16 Sep 2003 17:16 PDT
Hi Horseradish ~

When you view the file via the web, is there an error message like one
would get if weren't coded correctly?

and for calling an include that resides in the same folder, the code
should read:

<!--#include file="nameoffile.txt" -->

However, the ssi is relative, so if your file ends up in a different
location due to being produced by the cgi file, you would have to
change your ssi code to reflect the location of the .txt file in
relation to where the file is actually ending up.

Did that make any sense?

Where does the page called by the cgi file actually end up in relation
to your .txt file? That sounds like the problem.

Serenata

Request for Question Clarification by joseleon-ga on 16 Sep 2003 23:14 PDT
Hello, horseradish:

  As far as I know you cannot insert SSI directives into a page
produced by a CGI. The reason is simple, when you request the CGI to
the webserver, the server executes the CGI and echoes the output
"directly" to the clients browser. SSI directives also need to be
preprocessed by the webserver, so that's why it doesn't work, because
the results of the CGI aren't preprocessed by the webserver.

This is my experience on this matter, if you are interested on it, I
can post a full answer with references to the problem.

Regards.

Clarification of Question by horseradish-ga on 19 Sep 2003 10:05 PDT
Thanks for your help both of you. If it's definitely true that I can't
pull the ssi in to a cgi-generated page, then I won't bother trying
the first suggestion. Yes I'd appreciate any further info you have on
this, thank you very much.
Answer  
Subject: Re: cgi pulls html doc with a ssi - ssi doesn't work
Answered By: joseleon-ga on 22 Sep 2003 01:47 PDT
Rated:5 out of 5 stars
 
Hello, horseradish:

  I had the same problem a long time ago, I needed to mix PHP and SSI
directives and after perform some research I came to the conclussion
that it's not possible, at least, in the strict meaning of the phrase.
The reason is simple, it's the way the webserver works:

-When you call a CGI (PHP, Perl, etc), the webserver executes the
program in the server
-That program produces some output
-That output it's directly echoed to the client's browser, that is,
it's not processed again by the webserver looking for SSI directives

This doesn't mean you can't mix CGI with SSI includes, but maybe you
have to look in reverse, that is, call the CGI from the HTML page
using SSI, of course, this is not what are you looking for, but I
include it as extra information.

Apache Tutorial: Introduction to Server Side Includes	
http://httpd.apache.org/docs/howto/ssi.html.html

You can execute a CGI and dump the results into the page using SSI:

<!--#include virtual="/cgi-bin/counter.pl" -->

On the other hand, you can *emulate* in your CGI the way SSI works if
the SSI command it's simple, for example, include another document, or
just call any other CGI, if you want to elaborate more on this
direction, please, request for a clarification.

Also, if you use Apache, you can perform an apache subrequest to
emulate the SSI command, if you want to elaborate more on this
direction, please, request for a clarification.

These are some references to the same problem of yours:

I am having trouble using SSI(Server side includes) from cgi using
perl
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=E693DE68445C064FA112BAFE0A5EFD25012B3528%40exchange.nj.aptegrity.com&rnum=7&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3Dserver%2Bside%2Bincludes%2Bcgi%26btnG%3DGoogle%2BSearch

Apache: can cgi output be parsed for Server-side includes?
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=Dp5LwE.7I%40uns.bris.ac.uk&rnum=8&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3Dserver%2Bside%2Bincludes%2Bcgi%26btnG%3DGoogle%2BSearch

In software, it's very difficult to find something that cannot be
done, the problem is to find the way to achieve the same results in
another way, so if you want to continue investigating, maybe we can
find a way to get your job done.

Search strategy

server side includes cgi
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=server+side+includes+cgi&btnG=Google+Search

Regards.
horseradish-ga rated this answer:5 out of 5 stars
excellent full answer, thanks

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy