Solved

how to include SSI in CGI(perl) script?

Posted on 1998-06-22
19
574 Views
Last Modified: 2013-11-18
Greetings,

Does anybody know how to include a SSI into a perl script? here is an example:
#! /usr/bin/perl -w

select(STDOUT); $|=1;

print <<EOF;
Content-TYPE: text/html

<html>
....

<address>
Last Updated and Validated  on <!--#flastmod file="addentry.pl" -->
</address>
</body></html>
EOF

I know I could use stat or lstat function to get the result. just curious about how to do
it in SSI.

Thanks in advance

Peggy
0
Comment
Question by:pyang051597
  • 8
  • 4
  • 4
  • +2
19 Comments
 
LVL 6

Expert Comment

by:alamo
ID: 1207991
Normally the server doesn't check the CGI output for SSI directives, as it would waste server time. You have to configure the server to tell it to parse .cgi (or .pl) output for SSI.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1207992
#You could also
print <<EOF;
.
Last Updated and Validated on @{[scalar localtime ((stat"addentry.pl")[9])]}
.
EOF
0
 

Author Comment

by:pyang051597
ID: 1207993
How to configure the server to parse cgi output for SSI?

I increased the points, hoping you are more interested.


0
 

Author Comment

by:pyang051597
ID: 1207994
How to configure the server to parse cgi output for SSI?

I increased to points, hoping you are more interested.


0
 
LVL 6

Expert Comment

by:alamo
ID: 1207995
Well, that's a good first step, next you need to tell us what server you are using :-)
0
 
LVL 2

Expert Comment

by:tpryor
ID: 1207996
print `your_ssi.cgi`;

that would do it.

GL
t
0
 

Author Comment

by:pyang051597
ID: 1207997
for simplicity, let's say APACHE server.
0
 
LVL 2

Expert Comment

by:tpryor
ID: 1207998
oh i see, you are just curious.  you dont actually want to execute another (SSI) cgi script.

you wouldnt really configure the server to parse cgi output.

because it would be more efficent to call the (SSI) script within your perl script.

you just want to know how to configure your server that way so you can make sure that it is not configured that way to increase performance.  

oh, now I get it <gr>

t

0
 

Author Comment

by:pyang051597
ID: 1207999
Yes, I like to know how to call the ssi script within perl script, but I dont know HOW, and I dont understand your "print `your_ssi.cgi`".  I think configuration of the server may be
easier.  

I am still interested in the answer, in both way, if possible

Thanks again.
 
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:tpryor
ID: 1208000
print `your.cgi` executes another script and puts it's output where it was called from in the first script. dont need to configure the server to get the same results, more efficient, and IMHO its eassier <gr>

t
0
 

Author Comment

by:pyang051597
ID: 1208001
Can you give me an example?

Thanks
0
 
LVL 2

Expert Comment

by:tpryor
ID: 1208002
yep, Ill make it simple but you could have it be as complicated as you like in the real world no restrictions on this because they are just perl scripts.

make two perl scripts
In one (the ssi) set it uo the normal way except you dont need to print out the server header line (content-type: text/html\n\n).

just do
print "this is out put from the ssi<br>\n";

In the other
set it up in the normal way and dont forget the header line.
print "this is out put from my cgi<br>\n"
print `ssi.cgi`; # make sure the files are in the same dir or
                                # include the full path path/ssi.cgi
print "here is some more out put from my cgi<br>\n";

that should give you an idea of how it works.  It is quite simple.

GL,
t
0
 

Author Comment

by:pyang051597
ID: 1208003
OK, i made 2 files, one is ssi.pl as follows:
#! /usr/bin/perl -w

print "this is out put from the ssi<br>\n";
print <<EOF;
Last Updated and Validated  on <!--#flastmod file="ssi.pl" -->
EOF

another file is called ssi_1.pl

#! /usr/bin/perl -w

select(STDOUT); $|=1;

print <<EOF;
Content-TYPE: text/html

<html>
<body>
EOF

print "this is out put from my cgi<br>\n" ;
print `./ssi.pl`;
print "</body>";
print "</html>";

but it did not work, what's wrong? I am on SUN workstation, using
APACHE server, the server has been configured so it SSI is included.

0
 

Author Comment

by:pyang051597
ID: 1208004
Sorry, tpryor, I have to reopen the question, since the way you told me didn't work.

Thanks for help
0
 
LVL 1

Accepted Solution

by:
mikegrb earned 100 total points
ID: 1208005
To answer you original question:

It is impossible (AFAIK).  If it where you would:
Add "AddHandler server-parsed .pl" to conf/srm.conf and then
'killall -HUP httpd' however the CGIs ending in .pl are now
treated as if they where .shtml and thus they are not executed
but simply parsed for SSI directives and sent to the browser.

You might take a look at
http://www.cgi-resources.com/Programs_and_Scripts/Perl/Server_Side_Include_Parsing/
and similiar sites and adapt an existing CGI to use as a require.


0
 
LVL 6

Expert Comment

by:alamo
ID: 1208006
Hi pyang,

As mikegrb says, Apache can not be configured to do SSI processing on the output of a script. (Their FAQ says they plan to add it). The link he gave has some good alternatives.

To explain why tpryor's approach didn't work - it was not a way to do <!--#flastmod file="ssi.pl" -->, it was a way to do <!--#exec cgi="ssi.pl" -->. So yes it was a way to simulate one feature of SSI (included scripts), but not the feature you originally asked for (flastmod).

The real answer was far simpler anyway, and now you have it.
0
 

Author Comment

by:pyang051597
ID: 1208007
Thank you very much.

Alamo, I wish I could give you some credits as well. but I guess
there is no way to split the points, right?:)


0
 
LVL 6

Expert Comment

by:alamo
ID: 1208008
Not easily, you have to ask customer service.

In this case that's not necessary, but thanks.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1208009
print <<EOF;
<address>
Last Updated and Validated  on <!--#flastmod file="addentry.pl" -->
<address>
EOF
#can be emulated with
print <<EOF;
<address>
Last Updated and Validated on @{[scalar localtime ((stat"addentry.pl")[9])]
<address>
EOF

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
File Find regex problem 4 60
jQuery or Javascript animation question 6 66
jQuery Date picker not working 16 109
Problem to picture file 3 68
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now