RE: [PHP] Automatic Headers and Footers
[snip] The reasonn for my difficult answer was because the criteria for his solution indicated that he did not want to modify the html pages themselves. Thus the above solution is invalid :| [/snip] I see what you are saying, but how much modification is too much? :) OK, another waythe HTML could be read into a page (fopen()) containing the header/footer stuff. You'd have to deal with identification of which page you want loaded, but shouldn't be too hard. Jay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Automatic Headers and Footers
On Mon, 9 Jun 2003 07:21:45 -0500, Jay Blanchard wrote: I see what you are saying, but how much modification is too much? :) OK, another waythe HTML could be read into a page (fopen()) containing the header/footer stuff. You'd have to deal with identification of which page you want loaded, but shouldn't be too hard. Here is what I ended up doing http://marc.theaimsgroup.com/?l=php-generalm=105484835424858w=2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Automatic Headers and Footers
On Mon, Jun 09, 2003 at 12:26:24PM -0500, Wendell Brown wrote: OK, another waythe HTML could be read into a page (fopen()) containing the header/footer stuff. You'd have to deal with identification of which page you want loaded, but shouldn't be too hard. Here is what I ended up doing http://marc.theaimsgroup.com/?l=php-generalm=105484835424858w=2 That works. I did something similar, not to add headers and footers, but to implement a simple templating system -- the HTML pages had text like __FIRSTNAME__ and __LASTNAME__ which had to be replaced with session variables. The site owner had some very strange ideas about how they wanted to design their site, and wanted to do the whole thing in FrontPage, yet customize pages using data from a PHP-based login. The basic idea is that the customer uploads pages (a few hundred of 'em) all under their DocumentRoot. I've got stuff like: $base=http://www.example.com;; // URL *without* trailing backslash $qu=' . ''; $href=(a href=[$qu ]*)($base)?/?([^$qu ]+\.html?); $repl=\\1/show.php?what=\\3; if (!file_exists($f)) { header(Location: $base/show.php?err=missing%20file:%20$f); } else if ($fd=file_get_contents($f)) { $fd = str_replace(__FIRSTNAME__, $_SESSION['fname'], $fd); $fd = str_replace(__LISTNAME__, $_SESSION['lname'], $fd); print $fd; } You could of course hide the URLs behind mod_rewrite with something like RewriteEngine On RewriteRule ^/.+\.php - [L] RewriteRule ^/(.+\.html) /show.php\?f=$1 [L] You could also make the arrays of the str_replace search and replace fields, if you had multiple things to change. But back to your issue -- Instead of __FIRSTNAME__ and __LASTNAME__, just manipulate body and /body, as you did with output buffering. I'm not sure if either solution has a performance edge over the other. In both cases, each of the HTML and PHP file get loaded once per page view, and whether the translation happens in PHP's output buffering or via mod_rewrite is probably insignificant. As always, multiple solutions to every problem. :) -- Paul Chvostek [EMAIL PROTECTED] Operations / Abuse / Whatever it.canada, hosting and development http://www.it.ca/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Automatic Headers and Footers
I would have to say yes it can be done. The way *I* would do it is like this: First, I would drop a .htaccess file that allows the HTML files to run through the PHP parser. Like this AddType application/x-httpd-php .php .html The in all of the HTML docs it would look like this: -HTML- -Head- -Title-This is a test-Title- -body- -h1-? include('header.inc'); ?-/h1- Well, did it work? -h3-? include('footer.inc'); ?-/h3- -/body- -/html- The next question that comes to mind is, are all the headers and footers static? Or will they rotate? You will have to have that php code in your HTML docs, otherwise they won't know how to add the header and footer. Wendell Brown wrote: Ok guys, I think I have a challenge for you (actually, I don't think this can be done, but I've been proven wrong every time I've made that assumption with php in the past, so I'll ask anyway). Here's the question: Is there a way to have php insert headers and/or footers into all of the html files in a given directory on the fly (not actually modifying the files)? And by this I mean take an existing valid HTML file and add headers and footers and end up with a valid HTML file. Now, before some of you get trigger happy and tell me to read the manual and point me to things like .htaccess, auto_prepend_file, google and the like, think about what I'm really asking It needs to insert the header after the -body- tag and put the footer in before the -/body- tag. It needs to do this without modifications to the HTML file. And yes, I understand that by default HTML files aren't going to be effected by the auto_prepend_file (since they aren't php files) - so it will require adding HTML to the list of php parsed file types. For instance, the goal would be to take the following code: -HTML- -Head- -Title-This is a test-Title- -body- Well, did it work? -/body- -/html- and convert it to this: -HTML- -Head- -Title-This is a test-Title- -body- -h1-This is a page header-/h1- Well, did it work? -h3-This is the footer-/h3- -/body- -/html- Can it be done? I don't think so, but I leave it up to your wiles to suggest a solution Thanks!!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Automatic Headers and Footers
Well, my understanding of mod_rewrite is nonexistent (heck, I'm not even sure that's the correct name), but I believe you do the following. Write a php script to parse the file and output it with the added lines you want where you want them. Then setup apache/php to accept something like http://www.yourserver.com/directory/phpscript/yourfile.html where directory is the path to where the files are located, phpscript is the php script (located (in directory)that parses the html files, and yourfile.html is... one of your HTML files. It's not ideal, but it will let you wrap something around existing HTML files without modifying them or their location. --- Wendell Brown [EMAIL PROTECTED] wrote: Ok guys, I think I have a challenge for you (actually, I don't think this can be done, but I've been proven wrong every time I've made that assumption with php in the past, so I'll ask anyway). Here's the question: Is there a way to have php insert headers and/or footers into all of the html files in a given directory on the fly (not actually modifying the files)? And by this I mean take an existing valid HTML file and add headers and footers and end up with a valid HTML file. Now, before some of you get trigger happy and tell me to read the manual and point me to things like .htaccess, auto_prepend_file, google and the like, think about what I'm really asking It needs to insert the header after the -body- tag and put the footer in before the -/body- tag. It needs to do this without modifications to the HTML file. And yes, I understand that by default HTML files aren't going to be effected by the auto_prepend_file (since they aren't php files) - so it will require adding HTML to the list of php parsed file types. For instance, the goal would be to take the following code: -HTML- -Head- -Title-This is a test-Title- -body- Well, did it work? -/body- -/html- and convert it to this: -HTML- -Head- -Title-This is a test-Title- -body- -h1-This is a page header-/h1- Well, did it work? -h3-This is the footer-/h3- -/body- -/html- Can it be done? I don't think so, but I leave it up to your wiles to suggest a solution Thanks!!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php = Mark Weinstock [EMAIL PROTECTED] *** You can't demand something as a right unless you are willing to fight to death to defend everyone else's right to the same thing. *** __ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Automatic Headers and Footers
On Thu, 05 Jun 2003 16:41:01 -0400, Tom Ray [Lists] wrote: First, I would drop a .htaccess file that allows the HTML files to run through the PHP parser. Like this AddType application/x-httpd-php .php .html -h1-? include('header.inc'); ?-/h1- Yeah, that would work but my goal was to not have to modify the html files at all. Actually, I figured it out (or at least have it working). I guess I knew it was possible, but I was hoping for a miracle cure like add_html_header. :) Anyway, here is what I ended up doing... .htaccess AddType application/x-httpd-php .htm .html php_value auto_prepend_file header.php php_value auto_append_file footer.php header.php ?PHP ob_start(); ? footer.php ?PHP $content = ob_get_contents(); ob_end_clean(); $header = \nh1This is a page header/h1; $footer = h3This is the footer/h3\n; $content = preg_replace( /(body[^]*)/i, $1$header, $content ); $content = preg_replace( /(\/body[^]*)/i, $footer$1, $content ); echo $content; ? Any other ideas or simpler ways to do it would be appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Automatic Headers and Footers
Yes it can be done, using the auto-prepend feature call a script that turns output buffering on. Then in the auto-appended script read the buffer a manipulate ith with the automatic header and footer. Thus you modify the content only and achieve what you want without modifying the actual HTML file. Cheers, Rob. -- .-. | Worlds of Carnage - http://www.wocmud.org | :-: | Come visit a world of myth and legend where | | fantastical creatures come to life and the | | stuff of nightmares grasp for your soul.| `-' Wendell Brown wrote: Ok guys, I think I have a challenge for you (actually, I don't think this can be done, but I've been proven wrong every time I've made that assumption with php in the past, so I'll ask anyway). Here's the question: Is there a way to have php insert headers and/or footers into all of the html files in a given directory on the fly (not actually modifying the files)? And by this I mean take an existing valid HTML file and add headers and footers and end up with a valid HTML file. Now, before some of you get trigger happy and tell me to read the manual and point me to things like .htaccess, auto_prepend_file, google and the like, think about what I'm really asking It needs to insert the header after the -body- tag and put the footer in before the -/body- tag. It needs to do this without modifications to the HTML file. And yes, I understand that by default HTML files aren't going to be effected by the auto_prepend_file (since they aren't php files) - so it will require adding HTML to the list of php parsed file types. For instance, the goal would be to take the following code: -HTML- -Head- -Title-This is a test-Title- -body- Well, did it work? -/body- -/html- and convert it to this: -HTML- -Head- -Title-This is a test-Title- -body- -h1-This is a page header-/h1- Well, did it work? -h3-This is the footer-/h3- -/body- -/html- Can it be done? I don't think so, but I leave it up to your wiles to suggest a solution Thanks!!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Automatic Headers and Footers
[snip] Yes it can be done, using the auto-prepend feature call a script that turns output buffering on. Then in the auto-appended script read the buffer a manipulate ith with the automatic header and footer. Thus you modify the content only and achieve what you want without modifying the actual HTML file. [/snip] There are so many ways to skin this cat. You could (as you said, it will require adding HTML to the list of php parsed file types) have the header, body, and footer files read into a single file and then output. You could do something like this ... (a lot of folks use the following simple method to include navigation in web pages)... html head/head body ?php include(headerfile.inc); ? ... other html ... ... other html ... ... other html ... ... other html ... ?php include(footerfile.inc); ? /body /html I do not think that this needs to be difficult, but if you want more complexity you could have it. HTH! Jay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Automatic Headers and Footers
Jay Blanchard wrote: There are so many ways to skin this cat. You could (as you said, it will require adding HTML to the list of php parsed file types) have the header, body, and footer files read into a single file and then output. You could do something like this ... (a lot of folks use the following simple method to include navigation in web pages)... html head/head body ?php include(headerfile.inc); ? ... other html ... ... other html ... ... other html ... ... other html ... ?php include(footerfile.inc); ? /body /html I do not think that this needs to be difficult, but if you want more complexity you could have it. The reasonn for my difficult answer was because the criteria for his solution indicated that he did not want to modify the html pages themselves. Thus the above solution is invalid :| Cheers, Rob. -- .-. | Worlds of Carnage - http://www.wocmud.org | :-: | Come visit a world of myth and legend where | | fantastical creatures come to life and the | | stuff of nightmares grasp for your soul.| `-' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php