Gossamer Forum
Home : Products : Links 2.0 : Customization :

Can someone write a FAQ for Using SSI on the CGI Pages?

Quote Reply
Can someone write a FAQ for Using SSI on the CGI Pages?
I was wondering if someone could quickly write instructions on how to add SSI calls to the add.cgi and othe cgi pages. It has something to do with creating routines and I would appreciate it if someone would explain how to do this. Thanks.

------------------
Quote Reply
Re: Can someone write a FAQ for Using SSI on the CGI Pages? In reply to
It really depends on what you want to do. If you want an include, then you could use this code:

open (INCL, "/path/to/included/file") or die "Can't: $!";
$inc = join ("", <INCL> );
close INCL;

and then use $inc wherever you want the included text printed.

If you want to run another program, then you could use:

$exec = `/path/to/program`;

and $exec will contain the output. Word of caution, the program might behave differently depending on if it was called from another script or from the web.

Hope this helps,

Alex
Quote Reply
Re: Can someone write a FAQ for Using SSI on the CGI Pages? In reply to
Like Alex said, its really up to what you want the SSI to do. If you are including simple text or HTML from a file, using the method for opening and outputing the file is fine.

However, if you are trying to input info outputted from another script, you may need to do alot of modifications. The reason for this is simply that a Web Server (like Apache) won't parse the HTML coming from yout CGI for SSI's embedded in the text output.

Also note that many CGI's when parsed through an SSI call have the Content header stripped by the web server. Its important, because you may end up outputting stuff like:
Quote:
Content-type:text/html

<HTML><BODY>Blah blah blah
foo foo foo
<!-- START MY INCLUDE -->
Content-type:text/html

<HTML><BODY>bar bar bar</BODY></HTML>
<!-- END OF INCLUDE -->
More Info
</BODY></HTML>

This is really a pain on Netscape which will shut down further output of your page after the first </HTML> tag. To alleviate this, you must change your initial script so that ONLY straight HTML is outputted and not header information.

Several ways to defeat this problem:

1) Execute the program you want to output as an SSI from within the CGI you are running:

print `/home/foo/public_html/cgi-bin/bar.cgi`;
** Keep in mind, you must use left quotes here, not right ones.
2) Paste in the code of the program you wish to include. Alot of banner programs already allow for this, and its not a good idea to do if the program you want to include is more than 5 to 10 thousand lines.
3) REQUIRE/USE the accompanying CGI and call the appropriate subroutine from within the program you wish to use.


------------------
Fred Hirsch
Web Consultant & Programmer
Quote Reply
Re: Can someone write a FAQ for Using SSI on the CGI Pages? In reply to
Hi Fred and Alex,

we had this question here very often already. But I think we never had a perfect solution.

$exec = `balala`;

works perfect. The only (and important) backdraw is, that "content type: text/html" is displayed every time I execute my banner script this way. Of course that disturbes and destroys the whole layout.

I there a way to execute my script via ssi from within another cgi WITHOUT this "content type" stuff?

I am using webadverts or webads.

Thanks in advance!

Michael