Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how to include SSI in CGI(perl) script?

Posted on 1998-06-22
19
580 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
To run CGI/perl on tomcat and connect to oracle database. 5 135
Perl tar error 8 66
What language/protocol is the Angular Chat? 2 83
Perl script to process a .csv file 18 44
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

789 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