http://qs321.pair.com?node_id=403230

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How do you create a cgi header that will appear on all pages. I am wanting to create a script that will be run on every page at the very top. Similar to how ColdFusion uses their application script. I am currently using a two frames. One contains a menu at the top, the other the relative information below. If user drags a button (ie image) from top frame to bottom, the page loads fullscreen with no frames (the menu dissappears). Thanks people.

Replies are listed 'Best First'.
Re: CGI header
by talexb (Chancellor) on Oct 28, 2004 at 03:35 UTC

    I'm not sure whether you're confused about the terms you're using.

    A CGI header isn't really something that exists .. there's an HTTP header which icnludes things like information about the cookie updates, and there's also whatever appears at the top of the web page, sy, a menu or something like that.

    If you're talking about the first kind, then your CGI should be able to control what HTTP headers go out -- usually you're using the venerable CGI or something more advanced like CGI::Application so that you don't have to get your hands dirty actually sending out those kinds of headers yourself.

    If you're talking about some kind of menu at the top of your page, then a templaet is probably what you're looking for .. I can highly recommend Template::Toolkit (and for the dyslexics in the audience, that's not Toolkit::Template) (see also the web site).

    Think about those two options and see if you can give us more information on what you're looknig for. it's difficult to answer correctly if the question is not clear.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: CGI header
by csuhockey3 (Curate) on Oct 28, 2004 at 06:29 UTC
    I might be misunderstanding the question, but I believe I did something similar to what you might need a long time ago. I put all of my header code in to a separate file and called it when needed throughout my CGI.(multiple pages, forms, error pages, confirmation page ...) it acted more like a bread crumbing, but maybe this is what you are looking for? I second the use of Template::Toolkit, but this was writen before I was comforatble with it, and can an alernative if you are limited to what you can use.
    My 'header' displayHeader.pl:
    sub displayHeader{ print <<DISPLAYINGHEADER; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!-- continue all of the junk you want to include in each page --> DISPLAYINGHEADER }

    From there, my CGI required the displayHeader file and called it like so:
    sub displayErrorPage{ &displayHeader; ... } sub displayConfirmationPage{ &displayHeader; print $cgi->p("Thank You"); ... }
    The two functions above are entered based on the return value of a form validation subroutine (error checking form input).
Re: CGI header
by BUU (Prior) on Oct 28, 2004 at 03:18 UTC
    You can't via CGI. Your best bet is to configure the webserver to always run some script before every other script, or something similar. For example, using apache and mod_perl, it is possible to configure a script that runs after every request and gets the full content that would be sent back to the request.