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

The code below
print $query->header(); print $query->start_html(-title=>"Submission Added",-head=>meta({-http +_equiv=>"refresh",-content=>"2;url=http://baz.perlmonk.org/main.cgi"} +)); print $query->end_html;
is printing the following HTML -
<HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1252 +"></HEAD> <BODY></BODY></HTML>
I want to print something like this
<HTML> <HEAD> <META HTTP-EQUIV="refresh" content="2;URL=http://www.yoursite.com/newp +age.htm"> <TITLE>Page has moved</TITLE> </HEAD> <BODY> whatever you want to write </BODY> </HTML>
Whats going wrong?

Replies are listed 'Best First'.
Re: Delayed Redirect using CGI.pm
by cLive ;-) (Prior) on May 14, 2002 at 02:04 UTC
    It needs to be within the head element like this (according to the docs:
    print start_html(-head=>meta( { -http_equiv => 'Refresh', -content => '2;URL=http://www.yoursite.com/newpag +e.htm' } ));

    cLive ;-)

    --
    seek(JOB,$$LA,0);

Re: Delayed Redirect using CGI.pm
by grep (Monsignor) on May 14, 2002 at 00:24 UTC
    what about:
    $query->redirect('http://baz.perlmonk.org/main.cgi'); Note: Do not use '$query->header()' with this

    You can read about the redirect method at www.perldoc.org



    grep
    Unix - where you can throw the manual on the keyboard and get a command
      Well, I actually want a delayed redirect - one that will thank the submitter for making an addition to my website - just like when you post to an ikonboard.
Re: Delayed Redirect using CGI.pm
by belg4mit (Prior) on May 14, 2002 at 01:14 UTC
    I sincerely doubt CGI is printing windows charset headers. I suspect you are using IE, don't. IE reformats the HTML of a site and is thusly utterly useless for "debugging" a design. Try Amaya, Netscape, Mozilla, Opera, Lynx, or even telnet.

    Undefined subroutine &main::meta called at - line 3, <STDIN> line 1.
    It's -meta{} not meta().

    --
    perl -pew "s/\b;([mnst])/'$1/g"

      It's -meta{} not meta().

      While -meta is the recommended way of handling the majority of meta tags, current versions of CGI.pm (2.752+, possibly earlier) don't advocate it's use for generating HTTP-EQUIVs, instead saying...

      To create an HTTP-EQUIV tag, use the -head argument as described below.

      ... and then under -head (reformatted for clarity) ...

      To create an HTTP-EQUIV tag, use something like this:

      print start_html( -head => meta( { -http_equiv => 'Content-Type', -content => 'text/html', } ), );

          --k.


      Update: Added CGI.pm version number.

      Update II: On second glance, the current recommended method (ab)uses a feature in CGI's that turns any unknown CGI methods into (X)HTML...

      $ perl -MCGI=foo -le 'print foo({-bar => "baz"})' <FOO BAR="baz">
        And yet meta() gives the error above (UPDATE: oic, it's an optional export (though I cannot find the subroutine). we were not told that symbols were being explicitly imported...). The CGI here (v2.56) states:
        There is no support for the HTTP-EQUIV type of <META> tag. This is because you can modify the HTTP header directly with the header() method. For example, if you want to send the Refresh: header, do it in the header() method: print $q->header(-Refresh=>'10; URL=http://www.capricorn.co +m');
        No meta() anywhere. Refresh is a possible value of the HTTP-EQUIV meta tag.

        UPDATE: I see that the current version is 2.81, wahoo. Hrmm. Oh well. Seems to me it's be nicer to use the actual HTTP header than the meta tag anyways, given the option. But it looks like TIMTOWTDI

        --
        perl -pew "s/\b;([mnst])/'$1/g"