Gossamer Forum
Home : General : Perl Programming :

call ssi in a cgi?

Quote Reply
call ssi in a cgi?
Is it possible to execute an ssi (include virtual or exec cgi) command within a cgi script? If yes, how?

I also want to include header and footer files in some cgi scripts. The other option I am thinking of is

require header.txt
and then
print "header.txt";
not sure if that will work.

Give me some feedback.
Thanks
Quote Reply
Re: call ssi in a cgi? In reply to
You can not use SSI calls in cgi scripts (or perl scripts). What you have to do is add sub-routines and then call the sub-routines with the following codes:

Code:
subroutine;

To print header and footer files, there is a FAQ in the LINKS section of the Resource Center for doing this. It can be applied to other cgi and perl scripts.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: call ssi in a cgi? In reply to
Thanks Eliot. The resource center thing didn't work. But I found a footer subroutine, that I modified. Problemo solved.
Quote Reply
Re: call ssi in a cgi? In reply to
What do you mean it didn't work? If you used the sub_footer and sub_header routines and call them in the following:

Code:
print header;

THEN it will work!

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: call ssi in a cgi? In reply to
hmm... print header;?

I created a sub where I copied that routine an on top I tried calling the sub like

&site_header;

If it makes any difference, I am using this with any cgi script and not with links as an include. I want any cgi script to read the text file and print it when the sub is called.

For now I am fine. Like I said I hacked a sub.

Thanks.
Quote Reply
Re: call ssi in a cgi? In reply to
Oops...Forgot the & sign. Oh well...Anyway, you figured out a solution and that's all that matters.

Well, I use the same sub-routines in that FAQ in ALL my cgi scripts to print common header and footer files throughout my sites.

Wink

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: call ssi in a cgi? In reply to
Just a FYI, PERL 5 does not require the '&' to call a subroutine. It can be called both ways. Just make sure you are printing the Content-type header in your top routine.
Code:
sub top {
print "Content-type: text/html\n\n";
open(TOP, "/path/to/top/page") | | die "Can't open top";
while (<TOP> ) {
print $_;
}
close(TOP);
}

Bottom Routine
Code:
sub bottom {
print "Content-type: text/html\n\n";
open(BOTTOM, "/path/to/bottom/page") &#0124; &#0124; die "Can't open top";
while (<BOTTOM> ) {
print $_;
}
close(bottom);
}

call the routines like this:
&top; OR top;
&bottom; OR bottom;





Chris Ellenburg

------------------
WFMY-TV Webmaster
Quote Reply
Re: call ssi in a cgi? In reply to
i don't think you should print the content-type headers both times..

also..

you can put add a little twist..

Code:
sub insert {
my $file = shift;
open FILE, $file;
my @file = <FILE>;
close FILE;
return join "\n", @file;
}

and call it by

Code:
print insert ('/path/of/file/to/insert.txt');

jerry
Quote Reply
Re: call ssi in a cgi? In reply to
Widgets,

You are absolutely right, that copy and paste thing will get you every time.

Chris Ellenburg

------------------
WFMY-TV Webmaster
Quote Reply
Re: call ssi in a cgi? In reply to
Hi

I thought that I'd add to this thread rather than starting a new one.
I didn't notice anyone answer the question on how to include SSI in cgi output for include virtual's.

I know that links 2 does this as I have include virtuals in my templates and they get parsed and displayed correctly, can any one tell me how this is done? I've looked through the source code but all the regex's start to confuse me Smile

Cheers


------------------
Col


[This message has been edited by colr (edited January 02, 2000).]
Quote Reply
Re: call ssi in a cgi? In reply to
It has been addressed and discussed.

To include other cgi scripts and "calls" in other cgi scripts, you have to first create a sub-routine, and then call that sub-routine like the following:

Code:
print &buyaperlbook;

LOOK at the example widgetz provided. You cannot use SSI calls in cgi scripts. BUT you can include codes from other cgi scripts in the form of sub-routines and use the print command to call those sub-routines.

If this doesn't make sense...search the perl.com site for some tutorials that you can try to give you a better understanding.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------