Gossamer Forum
Home : General : Perl Programming :

Include header/footer files in cgi script

Quote Reply
Include header/footer files in cgi script
Hello,

I have header and footer files that are placed into web pages by SSI's. I'd like to include these into CGI scripts but other than pasting them in I know of no other way. Does someone have a script fragment that will read these files and place them where I need them to be??

Thanks
Quote Reply
Re: Include header/footer files in cgi script In reply to
What code are you using in the main html pages to load the header/footer files?

If it's
<!--#include virtual="footer.htm" --> that you are using, then just include that statement in your CGI script.

print "<!--#include virtual=\"footer.htm\" -->";

Don't forget the \ slashes when using " marks for paths.
Quote Reply
Re: Include header/footer files in cgi script In reply to
 
Code:
open (FILE, "/path/to/file") or die "Can't open: $!";
$include = join ("", <FILE> );
close FILE;

and then just use $include wherever you want to print it.

Hope this helps,

Alex
Quote Reply
Re: Include header/footer files in cgi script In reply to
                    Do you just want to store the contents of a file in a variable?

if (!$leftmenu) {
open (MENU, "leftmenu.html") or die $!;
$leftmenu = join ("", <MENU> ;
close MENU;
}

The if statement will make it so the file is only opened once (assuming this will be in
some sort of loop).