I work for a small college, and often write Perl scripts that create web pages and interface with MySQL databases.
We recently redid our main college website, and there is a lot of PHP in the new site design. I want to include the PHP includes in my Perl documents, but I haven't been able to get it to work. The reason for this, I believe, is because the files I create have an extension of .pl or .cgi. If I create an HTML file with PHP embedded in it, and give the file the extension .php, it works just fine. But the way I do it, my files look something like this:
*************Code Follows***************
#!/usr/local/bin/perl
$¦ = 1;
print "Content-type: text/html\n\n";
print <<end_of_html_form;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>My College: Contacts</title>
</head>
<body>
<?php include ('/webdata/docroot/includes/template/accessibility.php');?>
</body>
</html>
end_of_html_form
*************End of Code***************
Let's say that code is in a file called, "hello.pl". When I visit [mycollege.edu...] the php includes don't work.
If I created the same HTML file, but instead of making it a Perl file that generates the HTML, just made it straight HTML, then the PHP includes would work.
Any ideas of what I can do to make it work?
Thanks.........Doug
Normally I would say you can do an include without using PHP, using perl, or more appropriately Server Side Includes, but since your included file appears to be a php script you will want it to be in a PHP file so it executes as it's being parsed. There is a possibility you can use the perl exec command on the include, but I don't know.
[search.cpan.org...]
The scenario I had was for an enquiry form, the Perl script opened a SHTML file and outputted it as a success page for the user. The page included all the site standard menus and things, and I didn't want to lose this functionality.
I wrote this simple function which you could very easily adapt, it searches a file, in this case SHTML, copies it, but if it comes upon a #include line it splices that code in instead (by calling itself). Also handles nested includes.
sub SHTMLtoHTML {
my $file = shift;
$file =~ s/^\///;
open FILE, $file;
my @inhtml = <FILE>;
my @outhtml;
close FILE;
foreach( @inhtml) {
my $includefile = $1 if( m/<!-- #include virtual="(.*?)" -->/);
if( $includefile) {
my @includehtml = SHTMLtoHTML( $includefile);
push( @outhtml, $_) foreach( @includehtml);
} else {
push( @outhtml, $_);
}
}
return @outhtml;
}
What does CGI::SSI do?
Ideally there should be a way to tell the server to process this PL file as an SHTML file.
you could try serving the document with mime type text/x-server-parsed-html instead of text/html.
you might have to enable includes [httpd.apache.org] for this to work.