Cael
05-28-2001, 12:32 PM
How can I do so?
![]() | View Full Version : Enable SSI for cgi-scripts... Cael 05-28-2001, 12:32 PM How can I do so? Dim8 05-28-2001, 12:45 PM I don't think that's possible. However there is a way. And I use it for my estimate script (http://www.dim8.net/cgi-bin/estimate.pl). All I do is where I want a txt file to be inserted, I use this code: open(INF,"menu.txt") or dienice("Can't open menu.txt: $!"); @ary = <INF>; close(INF); foreach $line (@ary) { chomp($line); print "$line"; } And it adds the menu.txt file right where I want it. =0 cirrusrex 05-28-2001, 01:21 PM Ditto, its not possible (at least I am fairly certain). You could write or find a SSI parser for perl/python/[insert your favorite scripting language here] instead. Regardless, why would you want to use SSI when you are using a CGI script? Its just easier to let the script take care of that stuff instead... (SH)Saeed 05-28-2001, 01:35 PM The above code is good, but here's an even better one.. put this code at the end of your CGI script. sub rFile { if(-f $_[0]) { open(FILE, $_[0]) || die "Could not open $_[0] : $!"; while(<FILE>) { print $_; } close(FILE); } else { die "$_[0] does not exist"; } } Now during your script you can call this subroutine as many times as you want by simply adding the following to your script (where ever you want the SSI replacement): &rFile("dir/file.txt"); Simply replace "dir/file.txt" with the path and filename of your file. Keep in mind that this script also makes sure that the file exists prior to opening it. Saeed Dim8 05-28-2001, 02:05 PM Yeep.. that code is much better. It's much easier for me to add only 1 line of coding to have a file inserted than using that code. Thanks for the code.. I've changed my scripts to start using that code! =0 (SH)Saeed 05-28-2001, 02:17 PM I'm glad I could help, feel free to email me if you need other programming/database work done. Cael 05-28-2001, 02:25 PM Thanks pal. Actually my client asked for it. I don' t know he want to use it, but it's just not my business. Voodoo Web 06-13-2001, 03:23 PM With Apache 2 it is possible, but it is still beta. Apache modules may now be written as filters which act on the stream of content as it is delivered to or from the server. This allows, for example, the output of CGI scripts to be parsed for Server Side Include directive by mod_include. - domi huck 06-14-2001, 08:50 AM Check into a Perl Module called FastTemplate.pm. This module is an OO perl module that can parse HTML template files with variable subsitutions. This may need more than what they need, but FastTemplate.pm is a nice way to seperate your HTML code from the perl code. If you don't need any variable interpolations, then use one of the methods above. |