Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] How to do a CGI redirect with arguments?

Expand Messages
  • merlyn@stonehenge.com
    ... hooyar66 The problem I am having is that I can never get the arguments hooyar66 successfully sent! hooyar66 Redirect without arguments works fine - but
    Message 1 of 4 , Jan 14, 2009
    View Source
    • 0 Attachment
      >>>>> "hooyar66" == hooyar66 <hooyar66@...> writes:

      hooyar66> The problem I am having is that I can never get the arguments
      hooyar66> successfully sent!

      hooyar66> Redirect without arguments works fine - but the various approached
      hooyar66> I've tried to send arguments all fail.

      So, let's go to the authority.. the manpage for "perldoc CGI":

      GENERATING A REDIRECTION HEADER

      print redirect('http://somewhere.else/in/movie/land');

      Sometimes you don't want to produce a document yourself,
      but simply redirect the browser elsewhere, perhaps choos-
      ing a URL based on the time of day or the identity of the
      user.

      The redirect() function redirects the browser to a differ-
      ent URL. If you use redirection like this, you should not
      print out a header as well.

      You should always use full URLs (including the http: or
      ftp: part) in redirection requests. Relative URLs will
      not work correctly.

      You can also use named arguments:

      print redirect(-uri=>'http://somewhere.else/in/movie/land',
      -nph=>1,
      -status=>301);

      The -nph parameter, if set to a true value, will issue the
      correct headers to work with a NPH (no-parse-header)
      script. This is important to use with certain servers,
      such as Microsoft IIS, which expect all their scripts to
      be NPH.

      The -status parameter will set the status of the redirect.
      HTTP defines three different possible redirection status
      codes:

      301 Moved Permanently
      302 Found
      303 See Other

      The default if not specified is 302, which means "moved
      temporarily." You may change the status to another status
      code if you wish. Be advised that changing the status to
      anything other than 301, 302 or 303 will probably break
      redirection.

      Looks like there's no other args, so I'm not sure why you'd
      try randomly putting parameters down there.

      Presuming your redirect landing page can take url-based parameters,
      you should construct a url that contains the parameters, and pass
      that to your -uri=> parameter in the redirect call. One easy
      way to do this is with the "URI" module. "perldoc URI" for details.

      use URI;
      my $target = URI->new("http://your.host.here/path/to/your.landing.url");
      $target->query_form(key1 => 'value1', key2 => 'value2');
      print redirect($target->canonical);


      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
      See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
    • hooyar66
      ... approached ... 777 0095 ... discussion ... That s fantastic - many thanks Randal. ... authority is the word - the other sources I used didn t state a
      Message 2 of 4 , Jan 14, 2009
      View Source
      • 0 Attachment
        --- In perl-beginner@yahoogroups.com, merlyn@... wrote:
        >
        > >>>>> "hooyar66" == hooyar66 <hooyar66@...> writes:
        >
        > hooyar66> The problem I am having is that I can never get the arguments
        > hooyar66> successfully sent!
        >
        > hooyar66> Redirect without arguments works fine - but the various
        approached
        > hooyar66> I've tried to send arguments all fail.
        >
        > So, let's go to the authority.. the manpage for "perldoc CGI":
        >
        > GENERATING A REDIRECTION HEADER
        >
        > print redirect('http://somewhere.else/in/movie/land');
        >
        > Sometimes you don't want to produce a document yourself,
        > but simply redirect the browser elsewhere, perhaps choos-
        > ing a URL based on the time of day or the identity of the
        > user.
        >
        > The redirect() function redirects the browser to a differ-
        > ent URL. If you use redirection like this, you should not
        > print out a header as well.
        >
        > You should always use full URLs (including the http: or
        > ftp: part) in redirection requests. Relative URLs will
        > not work correctly.
        >
        > You can also use named arguments:
        >
        > print redirect(-uri=>'http://somewhere.else/in/movie/land',
        > -nph=>1,
        > -status=>301);
        >
        > The -nph parameter, if set to a true value, will issue the
        > correct headers to work with a NPH (no-parse-header)
        > script. This is important to use with certain servers,
        > such as Microsoft IIS, which expect all their scripts to
        > be NPH.
        >
        > The -status parameter will set the status of the redirect.
        > HTTP defines three different possible redirection status
        > codes:
        >
        > 301 Moved Permanently
        > 302 Found
        > 303 See Other
        >
        > The default if not specified is 302, which means "moved
        > temporarily." You may change the status to another status
        > code if you wish. Be advised that changing the status to
        > anything other than 301, 302 or 303 will probably break
        > redirection.
        >
        > Looks like there's no other args, so I'm not sure why you'd
        > try randomly putting parameters down there.
        >
        > Presuming your redirect landing page can take url-based parameters,
        > you should construct a url that contains the parameters, and pass
        > that to your -uri=> parameter in the redirect call. One easy
        > way to do this is with the "URI" module. "perldoc URI" for details.
        >
        > use URI;
        > my $target = URI->new("http://your.host.here/path/to/your.landing.url");
        > $target->query_form(key1 => 'value1', key2 => 'value2');
        > print redirect($target->canonical);
        >
        >
        > --
        > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
        777 0095
        > <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        > Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
        > See http://methodsandmessages.vox.com/ for Smalltalk and Seaside
        discussion
        >

        That's fantastic - many thanks Randal.

        >So, let's go to the authority.. the manpage for "perldoc CGI":

        "authority" is the word - the other sources I used didn't state a
        fixed list of args... so I wrongly assumed I could create my own.

        Thanks again
        NJH
      • david wright
        ... yup, as advertised. ... yup, I don t see the redirect method accepting an hashref as a arg in the docs. ... yup, again, I don t see the redirect method
        Message 3 of 4 , Jan 14, 2009
        View Source
        • 0 Attachment
          > print
          > $q->redirect(-url=>'http://pubswww.kl.imgtec.org:8080/cgi-bin/displaytest.cgi');
          > # No arguments works

          yup, as advertised.

          > print
          > $q->redirect(-url=>'http://pubswww.kl.imgtec.org:8080/cgi-bin/displaytest.cgi',
          > \%args); # This fails

          yup, I don't see the redirect method accepting an hashref as a arg in the docs.

          > print $q->redirect # # This fails
          > too!
          > (
          >
          > -url=>'http://pubswww.kl.imgtec.org:8080/cgi-bin/displaytest.cgi',
          > -nph=>1,
          > {
          >
          > 'never' => 'hi',
          >
          > 'happen' => 'ho'
          > }
          > );

          yup, again, I don't see the redirect method accepting an hashref as a arg in the docs.

          You can of course accomplish what you seek by building up your url itself.

          my $url = 'http://pubswww.kl.imgtec.org:8080/cgi-bin/displaytest.cgi';
          $q->redirect(-url=> $url.'?will=hi&happen=ho');

          (it's possible I am missing in the docs how to accomplish it via a redirect with args, try perldoc CGI, if you haven't already)

          +David


          --- On Wed, 1/14/09, hooyar66 <hooyar66@...> wrote:

          > From: hooyar66 <hooyar66@...>
          > Subject: [PBML] How to do a CGI redirect with arguments?
          > To: perl-beginner@yahoogroups.com
          > Date: Wednesday, January 14, 2009, 1:46 PM
          > Hi
          >
          > I have the following two scripts test.cgi &
          > displaytest.cgi
          >
          > test.cgi is intended to redirect itself to displaytest.cgi
          > and send
          > some arguments.
          >
          > The problem I am having is that I can never get the
          > arguments
          > successfully sent!
          >
          > Redirect without arguments works fine - but the various
          > approached
          > I've tried to send arguments all fail.
          >
          > I would really appreciate some help with this - I'm
          > sure/hope it's a
          > simple syntax issue
          >
          > Thanks
          > NJH
          >
          > test.cgi
          > ---------
          >
          > #!c:/perl/bin/perl.exe
          >
          > use strict;
          > use warnings;
          > use CGI;
          >
          > my $q = new CGI;
          >
          > my %args =
          > (
          > 'nev'   =>  'hi',
          > 'hod'   =>  'ho'
          > );
          >
          > print
          > $q->redirect(-url=>'http://pubswww.kl.imgtec.org:8080/cgi-bin/displaytest.cgi');
          > # No arguments works
          >
          > print
          > $q->redirect(-url=>'http://pubswww.kl.imgtec.org:8080/cgi-bin/displaytest.cgi',
          > \%args); # This fails
          >
          > print     $q->redirect # # This fails
          > too!
          >         (
          >            
          > -url=>'http://pubswww.kl.imgtec.org:8080/cgi-bin/displaytest.cgi',
          >             -nph=>1,
          >             {
          >                
          > 'never'   =>  'hi',
          >                
          > 'happen'   =>  'ho'
          >             }
          >         );
          >
          >
          >
          > print   "Content-Type: text/html\n\n",
          >         "The redirect seems to have
          > failed.";
          >        
          > ---
          >
          > displaytest.cgi
          > ---------------
          >
          > #!c:/perl/bin/perl.exe
          >
          > use warnings;
          > use strict;
          > use diagnostics;
          > use CGI;
          > use CGI::Carp qw(fatalsToBrowser);
          > use DBI;
          >
          > my $q = new CGI;
          >
          > print   $q->header(),
          >         $q->start_html(),
          >     '<h1>Test
          > redirection</h1>';
          >
          > print "Args: ", $q->param(), "<br>";
          >
          > foreach my $param($q->param())
          > {
          >     print "Initial: $param, Value:
          > ",$q->param($param),"<br>";
          > }
          >
          > $q->end_html;
          > exit();
          >
          >
          > ------------------------------------
          >
          > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
          > Groups Links
          >
          >
          >     mailto:perl-beginner-fullfeatured@yahoogroups.com
          >
          >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.