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

Hi Guys,

I have a problem that is probably fairly simple but is causing me reall problems and stress (deadline looming) :(

Thank you so much to anyone who can offer some advice on this one

I dont know how to handle the following problem. I thought I had the solution but it doesnt work and now I dont know if I'm even using the right approach. I'm still pretty new to perl. I can do some big scripts but I'm self taught so I havent had the benefit of a teacher to ask stupid questions to!

So:

I have a typical html page that contains a form. The form accepts a username and password and calls a script.

The script validates the user. Thats all fine and the code works perfectly.

But here's what I dont get:

Most webpages obviously have a lot of static content like menus and banners and stuff. To include this stuff I just got all the code from a typical page and put it into a heredoc in my script and output it like that. It didnt work.

So I guess my question is:

How do you include all the static content on a page cleanly.

The static html from my 'typical' html page contains ssi virtual include statements for things like the header and footer. Can ssi's be called in the cgi-bin

Another related question is- if I want to include a picture on the page that my script makes, do I need to make the link relative to the cgi-bin, or do I act like I'm in htdocs? I've seen behaviour that really confused me there?

Well thats it! Thank you to anyone who can offer some advice on any of the questions back there. I reall really appreciate it. You'll be making the sun shine again! :)

Kind Regards All

Simon

Replies are listed 'Best First'.
Re: Serving up static content with perl?
by Zaxo (Archbishop) on Sep 22, 2002 at 17:08 UTC
(jeffa) Re: Serving up static content with perl?
by jeffa (Bishop) on Sep 22, 2002 at 17:17 UTC
    You might find reading up on CGI::Application to be quite benficial, as well as the modules that Zaxo recommends.

    UPDATE: rob_au has written an excellent review on CGI::Application to help you get started.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Serving up static content with perl?
by dws (Chancellor) on Sep 22, 2002 at 19:43 UTC
    To include this stuff I just got all the code from a typical page and put it into a heredoc in my script and output it like that. It didnt work.

    If you grabbed a web page and embedded it in a heredoc, you probably forgot to include a valid HTTP response header. Add   Content-type: text/html at the top of the heredoc, followed by at least one blank line.

    That said, you're better off using one of the templating mechanisms, such as HTML::Template.

Re: Serving up static content with perl?
by Ryszard (Priest) on Sep 22, 2002 at 17:23 UTC
    Zaxo got it in one. Use a templating system. HTML::Template is one i've used extensively before, however others prefer other templating solutions.

    Build your html page as if it were a static page (ie it works) then slurp it up and spit it out with your templating system of choice.

    After you've got that down pat, its not too much of a leap to include your own content, or personalisation, (Welcome <user>)

Re: Serving up static content with perl?
by zengargoyle (Deacon) on Sep 22, 2002 at 23:11 UTC

    i doubt that SSI inside of CGI will work. but CGI inside of SSI will. let the server handle the html and insert your CGI for you.

    <!-- /my-cgi.html the server SSI will run my CGI --> <!--#include virtual="/standard/header.html" --> <hr><h1>Check out my cgi!</h1> <!--#include virtual="/cgi-bin/my-cgi.pl" --><hr> <!--#include virtual="/standard/footer.html" -->

    then your CGI can just be something simple.

    #!/usr/bin/perl -T # /cgi-bin/my-cgi.pl # $factoid = "No matter where you go, there you are..."; print <<_HTML_; <p>Factoid of the day: <em>$factoid</em></p> _HTML_ exit;
      Be careful. This is not an exec cmd. If you exec cgi or (preferrably) include virtual, you have to emit appropriate HTTP headers.
      print <<_HTML_; Content-type: text/html <p>Factoid of the day: <em>$factoid</em></p> _HTML_

      Makeshifts last the longest.

Re: Serving up static content with perl?
by bronto (Priest) on Sep 23, 2002 at 14:42 UTC

    If you are keen on diving into some XML you could also try AxKit.

    If are not compelled to leave Perl out: just learn some XPath syntax and use XPathScript.

    . Creating pages that have some fixed content is as easy(*) as writing your pages in some XML and having them transformed in HTML (and/or in any format you want) by a stylesheet

    Ciao!
    --bronto

    (*) of course, you can read easy the way you like: serious or ironic :-)

    # Another Perl edition of a song:
    # The End, by The Beatles
    END {
      $you->take($love) eq $you->make($love) ;
    }