PDA

View Full Version : Can CGI output be parsed as PHP?


Vroomfondel
01-10-2000, 04:32 PM
To maintain a consistent look and feel sitewide I write all my Perl scripts to use template files so that the output looks like the rest of my pages. Call me silly, but I've just always hated those blank, lifeless white CGI output pages. However, much of that template is written into the sites main pages via includes. Stuff that changes often, like the internal navigation links, is much easier to handle by included snippets rather than hand-coding the individual pages. I just can't seem to find a way around doing it for the CGI output pages. Normal HTML tags within the scripts are read and rendered okay, but specialized server-parsed tags like PHP and SSI are ignored.

Is there some sort of Apache voodoo that will force the server to parse the Perl output for PHP tags so I can use the same includes there as on the rest of the site?

Justin
01-10-2000, 04:56 PM
I do believe this could be done, technically, but I *strongly* recommend against trying to do this... what you are wanting to do is parse the script twice - once through Perl and then parsing its output through PHP... this would create a LOT of overhead...

What I usually do is simply save a copy of the source (eg, the HTML output) from the site as it is sent to the browser (after being parsed for PHP). This of course ends up being static, and will take a little bit of manipulation to get it to look the way you want it to, but then have the CGI print out the HTML to match (as closely as it can) the rest of the site.

I agree that most CGI's out there are dull and boring looking, even though they may do a great job performing whatever task they are meant to do. I usually write my own and do something similar to the above - making it fit in with the rest of the site.

Hope this helps.

------------------
Justin Nelson
FutureQuest Support

Vroomfondel
01-10-2000, 05:08 PM
That's kind of what I do now. I just create an HTML template that matches the site and use that in the CGI output. It's not ideal, but it beats the old boring CGI output pages. My problems come in when I change the included files and forget to edit the CGI scripts and templates to incorporate the new info. My mind isn't what it used to be, so rather than using much-needed brain cells to remember to edit all the important template files, I was hoping for a server-level solution to idiot-proof things. Sadly, in this case I won't be able to protect my site from me ;)

Thanks. I appreciate the advice

Dan Kaplan
01-10-2000, 08:28 PM
I think you're talking about the same sort of thing I do.[nbsp][nbsp]It's worked pretty well for me to effectively have a header and footer text file (my header usually includes the left side menu) and the rest of the pages are in a table that the header opens and the footer closes.[nbsp][nbsp]All of the HTML pages and cgi scripts pull in the same header and footer files, so I only have two (technically three, due to a banner rotation in the HTML header file) files to edit to effect every page on the site.[nbsp][nbsp]As long as I don't change the general structure, there's no reason for me to ever edit the cgi output.[nbsp][nbsp]Am I even close to answering what you were asking...?

Dan

Dan Kaplan
01-10-2000, 08:28 PM
I think you're talking about the same sort of thing I do.[nbsp][nbsp]It's worked pretty well for me to effectively have a header and footer text file (my header usually includes the left side menu) and the rest of the pages are in a table that the header opens and the footer closes.[nbsp][nbsp]All of the HTML pages and cgi scripts pull in the same header and footer files, so I only have two (technically three, due to a banner rotation in the HTML header file) files to edit to effect every page on the site.[nbsp][nbsp]As long as I don't change the general structure, there's no reason for me to ever edit the cgi output.[nbsp][nbsp]Am I even close to answering what you were asking...?

Dan

Justin
01-11-2000, 02:04 AM
Is there an echo in here? ;)

Dan - that works provided that you don't use any PHP in the files - though if include() is the only PHP feature you are using I would suggest going SSI personally...[nbsp][nbsp]My sites use a lot of PHP code all over the place - eg, random META tags, banner ads, browser detection to dynamically size text boxes and other browser-dependant features, and so on... so my header files usually contain quite a bit of PHP code. I was assuming that Vroom's do as well...

------------------
Justin Nelson
FutureQuest Support