Ask Leo! by Leo A. Notenboom

How do I include one HTML file inside another?

Search First! Then browse: Categories | Full Archive | By Date | Newsletter

Home » Web » Web Site Management

Comments

Read the article that everyone's commenting on.
RSS feed Subscribe to the RSS Feed for comments on this article.

Comment Page:  1  |  2  |  3  |  4 

The local IT guru said: "It is not possible to include HTML code to an existing html file. You have to edit all these 500 files and change the header manually."
No comment! Of course it is possible to edit 500 files at once and change strings in them, provided your local IT hero has not decided to have Micro$oft as OS and Livelink as web server.
Anyway, this hint helped me solving the problem, the local IT superman gave me week to finish the job. I had a lot of fun during this week ;o)

Cheers.

Posted by: Robert Persig at February 11, 2005 7:42 AM

this is just another more reliable verion of a previous post for php...


or

by doing it this way, you are making sure that the webserver no matter what brand will understand it, because >> alone is asp style..


the second choice >> include_once ensure that if a file being included to the page is already present it doesn't include it agaiin

Posted by: sindergoth at March 29, 2005 5:38 PM

Glad I found this, I make extensive use of ssi includes I have spent ages trying to figure how to pass VARS to ssi, I see this can't be done.

I would like to have a page with a number of link to static pages like /product/1001.html and /product/1002.html and have them appear in the current page (without frames) when clicked

The closest I can get to this is by modifying your script proxy.pl, I'm am sure there is a more elegant way, especialy since the pages I am linking to are on the same website?
Regards Roly

#!/usr/bin/perl
use LWP::Simple;
print "Content-type:text/html\n\n";

open (FILE, "header.txt") || die "cannot open file: $!";
undef $/; # read in file all at once
print ;
close FILE;

getprint ($ENV{'QUERY_STRING'});

open (FILE, "footer.txt") || die "cannot open file: $!";
undef $/; # read in file all at once
print ;
close FILE;

Posted by: Roland at September 18, 2005 6:14 PM

for people
require_once("./file.ext"); // Requires File only once
Require("./file.ext"); // Requires File
include("./file.ext"); // Includes file

Now I am learning php and im quite good at it so ill drop a few php methods.
I always have a tons of files.. i spread my code everywere and its neatly sorted. but sometimes like lets say you wanna make a dice script you would put
ReRoll";
?>

Posted by: MetaNeko at November 20, 2005 6:13 PM

I cannot seem to get proxy.pl to work at all, even locally. Am I correct that the script file should simply be as follows:

#!/usr/bin/perl
use LWP::Simple;
print "Content-type:text/html\n\n";
getprint ($ENV{'QUERY_STRING'});

Can someone please help? SSI is working fine locally, CGI is enabled, the script is chmod'd to 755 (as is the directory), and I've tried every variant thinkable for the links on the shtml pages. Please see the following examples:

At http://www.tcconcepts.com/pagetest1.shtml I'm using a normal include like so:

<!--#include virtual="page1.txt" -->

...which is pulling in the sample text (everything below the line) just fine from the referenced .txt file.

At http://tcconcepts.com/pagetest2.shtml I'm using:

<!--#include virtual="/cgi-bin/proxy.pl?page1.txt" -->

At http://tcconcepts.com/pagetest3.shtml I'm using:

<!--#include virtual="/cgi-bin/proxy.pl?/page1.txt" -->
(note additional slash)

Neither of these latter pages (using proxy.pl) works. Nor do any other variants of the link including "./", "../" etc. I've also tried referencing different (later) versions of Perl. I'm not even getting error messages. The space is created, it's just not populated with the content. Any ideas?

Posted by: Joe Formtester at December 18, 2005 4:58 PM

It's expecting a URL. So you'd want proxy.pl?http://whatever.... - that's the point of proxy.pl.

Posted by: Leo at December 18, 2005 5:48 PM

Understood. But when that didn't work, I thought I'd try local. In any event, see:

http://www.tcconcepts.com/pagetest4.shtml where I'm using the following:

<!--#include virtual="/cgi-bin/proxy.pl?http://www.comptonmfg.com/page1.txt" -->

Again, the space is created, but no content fills it. To my non-Perl brain, this implies that it's seeing the need to insert something, but not what that something is.

Posted by: Joe Formtester at December 18, 2005 6:58 PM

So just running http://tcconcepts.com/cgi-bin/proxy.pl?http://www.comptonmfg.com/page1.txt will test it outside of the SSI environment. It should just print the contents of the referenced file.

Obviously yours doesn't, and I'm not sure I see an obvious reason why. I would add a print statement before the getprint:

print $ENV{'QUERY_STRING'} . "\n";

That should simply ensure that the QUERY_STRING is coming in correctly. If it is (and I'd guess it is) then I would suspect some kind of configuration issue on your server that's preventing getprint from working.

Posted by: Leo at December 18, 2005 7:20 PM

Okay, that pulls in the URL, but not the contents of the URL.

The script now looks like this:

#!/usr/bin/perl
use LWP::Simple;
print "Content-type:text/html\n\n";
print $ENV{'QUERY_STRING'} . "\n";
getprint ($ENV{'QUERY_STRING'});

Using the http://www.tcconcepts.com/pagetest4.shtml link now pulls in text that reads "http://www.tcconcepts.com/page1.txt", rather than the HTML code that resides in that file.

Just curious. Could the fact that my version of LWP is 5.53 have anything to do with it? By the way, thanks for your help; I really appreciate it.

For what it's worth, what I'm trying to do is find a way to allow others (remote sites) to be able to insert an include (and perhaps a small cgi script like proxy.pl) that pulls actual code from a page on a site that I control. IF you have some other idea, I'm all for it.

Posted by: Joe Formtester at December 18, 2005 8:15 PM

It's possible that LWP is an issue, but then other things could be as well. I'd look at your error logs, and if you have shell access, telnet in or ssh in to the server and run the perl script directly from a command line and see if it does what you expect. See if you can get ANY "getprint" to work.

An alternative might be to try PHP if your server has it. A test.php in your regular (not cgi-bin) directory that has this will tell you if it would work:

<? include ("http://whatever"); >

This *may* work, if your PHP configuration has it enabled.

Posted by: Leo at December 18, 2005 8:20 PM
Comment Page:  1  |  2  |  3  |  4 
Read the article that everyone's commenting on.
RSS feed Subscribe to the RSS Feed for comments on this article.
Post a Comment

To post a comment on "How do I include one HTML file inside another?", please return to that article's main page.

Question? Ask Leo!