Secondly, how can I insert some HTML into a specific location in an HTML file and send the new file out to the browser (using php or cgi)?
1. You can't. You need frames for that.
2. You could put a variable in your php page and
then when the user does whatever triggers the inclusion of this html then assign the html to your empty variable (have to use sessions or form vars) and relocate to the current page.
Need much more detail on the second question give a good answer...
Nick
1. You can but it is very intensive. You essentially have to get your script to go get the page, might have to parse and cut it, and then display it. You would have to rewrite links etc. Really isn't worthwhile, it is most likely to be slow.
The method is, in essence, cloaking. I don't understand the reason why you need to do it this way. I also wonder about what you mean by external source. If it is somone else's site then use frames, if it is something you own then find a way to put it on the other site.
2. Nick has the gyst of it and a little more info may help us out.
2. I mean like this: you have 'http://www.abc.com/apage.html'
Then you call a script on your site: 'http://www.mysite.com/ascript.cgi'
This script ascript.cgi does this:
=> retrieve apage.html
=> find the words "insert here" on the page
=> insert html, say "<a href='abc'com<hellow></a>" after this location
=> output this new file to the browser
Are there some php or cgi examples how to do this, I don't need complicated parsing, just find a tag and insert after it, etc...
So that's the problem, if there are good solutions let me know...also, it should look good for search engines...
PHP fopen() funtion [php.net]
If filename begins with "http://" (not case sensitive), an HTTP 1.0 connection is opened to the specified server, the page is requested using the HTTP GET method, and a file pointer is returned to the beginning of the body of the response. A 'Host:' header is sent with the request in order to handle name-based virtual hosts.
Nick
include function [php.net]
2. You can do find and replaces like that using regular expressions, take a look at the other functions on the php.net. They have a whole list of regex functions. I sometimes split the file and then have a function in the replacable part that does the work. You have a header file include and then do your dynamic stuff, then include a footer file.
Nick's right, frames is the way to go for the other.
Inserting into the page could be a little tricky too if you are determined to have your added html in a specific location. Basically you are going to have to search for a string in the original HTML and then replace it with the same string + whatever you want to add.
Back in the heavy spam days I use to do a lot of this type of stuff for clients. I'd grab their page add some SE food and then feed it to the spiders on a "mirror domain". One thing I would do is cache the altered pages every few days to keep the script from bogging down the server.
But then again the dupe content may nab you too.
STEP 1: Create file index.php
<?
require 'http://yahoo.com/';
?>
If this file is on your server as index.php and you call it, it shows Yahoo in the browser AND the url in the address bar is your site...
STEP 2: Serve index.html as index.php in your .htaccess file
RewriteEngine on
RewriteBase /scripts/
RewriteRule ^index\.html$ index.php [T=application/x-httpd-php]
Voila, this should do exactly what I desire,
Only think is, I don't know what search engines would do to the above scheme or how to perhaps improve it for search engines...