in reply to SSI in CGI scripts?

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

Replies are listed 'Best First'.
RE: Re: SSI in CGI scripts?
by NeverMore (Acolyte) on Nov 12, 2000 at 11:47 UTC
    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

      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