I have existing html files that I would like to insert headers and footers onto. There are too may to do by hand. I would like to do some kind of search and replace to add the the code in the correct place server side. What's the best way to do this? Preferably in php or perl. Thanks.
Do you want to insert the header/footer statically (so a copy of it exists within each file), or have the files include a "master" header/footer file? - Shawn
With PHP, you can just do include 'header.php'; PHP: Then put in header.php all the html you want to go at the start of each page. Foxyweb, apparently is it possible to create a dynamic sitemap, but it really depends on your site as to how well it works.
Can you tell me more on the site map question? For instance what sort of site does it work well on? Thanks
Sorry, I dont really know much more, just read it on a forum somwhere. I'm sure hotscripts.com could furnish you with some auto sitemap code, and maybe even a tutorial.
I would like the header/footer to be inserted server side as the file is requested. I know I could manually add an include statement where needed in each file. I would prefer to have the code automatically inserted so that I don't really have to do anything else. An example of what I want to accomplish is basically what the free hosting sites do with advertising headers/footers. When you upload an html page to the free hosting site - they add an advertising header and footer server side without tampering with the rest of the page's html.
The best thing to do (that I can think of) would not be to alter each individual file, but use mod_rewrite to pass everything through a simple PHP script (or whatever scripting language you like) that does it for you on the fly. - Shawn
You could have your .htaccess file setup like so in the root of the website: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !passthru.php RewriteRule ^(.*) /passthru.php?file=$1 </IfModule> Code (markup): Have passthru.php in the root of your web directory as well... <?php readfile("header.inc"); readfile($file); readfile("footer.inc"); ?> PHP: header.inc and footer.inc also in the same folder (those of course are your header/footer files). Then any request for a file (regardless of directory) within the site will have header.inc added to the beginning and footer.inc added to the end. You could get trick within the passthru.php file and do a little better insertion (for example insert the header right after the <BODY> tag for example). But that should get you started... Ultimately the best thing to do would be to make the footer.inc file link to www.digitalpoint.com though. hahaha - Shawn
Thanks, that's exactly what I'm looking for. Do you know the php insert command right off the top of your head?
The command to search for the a particular tag on the existing html file that is being passed through and then insert the the header code.
Oh... there isn't a single command for that... you basically would need to read in the file, evaluate it and do some manipulation of the text instead of just using the readfile() command (which passes it right through).
Hey guys. Stop! The digital point script is a bit dangerous!! You should make sanity checks before opening the file or your passwords...... http://host.com/passthru.php?file=../../../../etc/xxx PHP has a directive to append files automatically. Check your php.ini file: " ; Automatically add files before or after any PHP document. auto_prepend_file = auto_append_file = " you may also set this in a .htaccess file.
Wouldn't work of course for non-PHP files... but you could setup Apache to run any file extension through the PHP parser. - Shawn