in reply to Re^3: Coding and Design Advice
in thread Coding and Design Advice

Hi,

I see what you're talking about. In your #3 step, how do I issue a http redirect to PayPal? I never did this before using a script so I'm not sure about the code. Otherwise, your idea would be perfect.

Can you help me out with the redirect code?

Thank you for your help and time.

Replies are listed 'Best First'.
Re^5: Coding and Design Advice
by g0n (Priest) on Apr 01, 2005 at 11:43 UTC
    The HTTP redirect using CGI is quite straightforward:

    use CGI; my $cgi = new CGI; print $cgi->redirect('http://thisistheurltoredirectto.com');

    You will need to do your redirect conditionally upon the content of $cgi->param('paymenttyperadiobutton') and remember that the redirect has to be the first header - don't issue a standard http header beforehand.

    g0n, backpropagated monk
      Hi,

      Yes, it certainly appears straightforward. I also understand that the redirect will be based on the result of the button that is selected.

      As for placing the redirect as the first header, do I place it before my conditional statement or after?

      I'm not sure I follow "has to be the first header".

      Thanks.
        OK, the code will be something like:

        #!/usr/bin/perl use strict; use CGI; my $cgi = new CGI; # construct and send confirmation emails here if you # want them to go to everyone if ($cgi->param('radiobutton') eq 'paypal') { # this sends a redirection header print $cgi->redirect('http://sendmetopaypal.com'); } else { # construct and send confirmation emails here if you # only want them to go to non paypal users print $cgi->header(), $cgi->start_html, "Thank you for booking, a confirmation email has been sent to +email\@address", $cgi->end_html; }

        What I meant by 'has to be the first header' is don't do this:

        #!/usr/bin/perl use strict; use CGI; my $cgi = new CGI; print $cgi->header; print $cgi->redirect('http://redirecttohere.com');

        I've got stuck on that one a couple of times :-) In other words, don't forget that redirect is a header in it's own right - it doesn't need a $cgi->header sending before it.

        g0n, backpropagated monk