Re: SSI in CGI scripts?
by chromatic (Archbishop) on Nov 12, 2000 at 07:13 UTC
|
AgentM's solution works only if you create the shtml file in the CGI, write it to the filesystem, and redirect to it.
Other solutions include Apache::SSI if you're running Apache or CGI::SSI if you're not.
The problem is, your web server won't know to run the SSI interpreter on the output of your script, so you need something to call that interpreter or something that does the same thing. | [reply] |
Re: SSI in CGI scripts?
by roberto (Acolyte) on Nov 12, 2000 at 07:21 UTC
|
Vanilla CGI doesn't support SSI, output from CGI is sent to the browser
directly (mod perl supports SSI - see Apache::SSI)
what do you whant to do with SSI that you cannot do with CGI?
Update: There is a module called CGI::SSI on CPAN,
although i don't see the need for SSI upon CGI maybe this is what you are lloking for... | [reply] |
Re: SSI in CGI scripts?
by a (Friar) on Nov 12, 2000 at 11:14 UTC
|
Okay, try:
(assuming (from other discussions) you're reading from
somewhere so your text is in $_):
if ( /\[include]\s*(\S+)\s*\[\/include]/ ) {
my $path = $1;
$path = s#.*/(.*)$#$1#; # delete any ../../ stuff
print "<!-- #include virtual=\"/secure_path/$path\" -->\n";
# include only from /secure_path
}
a | [reply] [d/l] |
|
|
I sort of modified that code:
if( $ThePost =~ /(\[include\])(\S+?)(\[\/include\])/ )
{
my $inpath = $1;
my $include = '<!--#include virtual="/directory/'.$inpath.'" -->';
$ThePost =~ s/(\[include\])(\S+?)(\[\/include\])/$include/ig;
}
This didn't work, however. I really can't do it through print. I have to add it to the variable $ThePost.
-NM | [reply] [d/l] |
|
|
Probably because you've got 3 set of parens, so:
$1 eq "[include]";
$2 eq <whatever path you wanted>
$3 eq "[/include]";
and your s/ would replace all of it by $include. Did you want:
$ThePost =~ s/(\[include\])(\S+?)(\[\/include\])/${1}$include${2}/ig;
or:
$ThePost = "[include]$include[/include]";
This won't work for multiple [include][/include]'s in the
same ThePost, though the first might. Guess I'm still not clear,
I thought you wanted to replace the include tags w/ the
ssi #include instruction for the filename found between
the tags. Don't see why you want to put your [include] tags
back in to the output stream.
a | [reply] [d/l] [select] |
Re: SSI in CGI scripts?
by AgentM (Curate) on Nov 12, 2000 at 07:11 UTC
|
Sure. Why not? A CGI script is only a program that interacts with a web server- otherwise, it is completely normal and functional. If you are generating .shtml files through a CGi script (a quizzical but acceptable thing to do), then writing a file is the same as if you had made a command line program to do the same:
use CGI;
...
open(FILE,"<webpage.shtml");
...
print FILE '<!--#exec cgi="somefunky.cgi"-->';
if it was created correctly, you'll be able to view your .shtml through your browser normally (watch permissions, locking, etc.).
AgentM Systems nor Nasca Enterprises nor
Bone::Easy nor Macperl is responsible for the
comments made by
AgentM. Remember, you can build any logical system with NOR.
| [reply] [d/l] |
|
|
actually, i did this: s/(\[include\])(\/\S+?)(\[\/include\])/ <!--\#include virtual="$2" --> /isg;<code> but this prints this: <code>< !--\#include virtual="$2" -->. What's the problem?
| [reply] [d/l] |
|
|
actually, i did this: s/(\[include\])(\/\S+?)(\[\/include\])/ <!--\#include virtual="$2" --> /isg; but this prints this: < !--\#include virtual="$2" -->. What's the problem?
| [reply] [d/l] [select] |