return value from cgi

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Bearden

    return value from cgi

    Greetings,

    I'm posting a form to a cgi application on another web site. The cgi returns
    a text message to the browser. How can I capture this text message and
    redirect based on the text.

    Example:
    if (text == "SUCCESS")
    Based in Waterloo, Ontario, BlackBerry is a leader in secure communications — helping businesses, government agencies and safety-critical institutions of all sizes secure the Internet of Things (IoT).

    else


    Thanks!


  • Daniel Tryba

    #2
    Re: return value from cgi

    Paul Bearden <paulbearden@sb cglobal.net> wrote:[color=blue]
    > I'm posting a form to a cgi application on another web site. The cgi returns
    > a text message to the browser. How can I capture this text message and
    > redirect based on the text.[/color]

    How are you posting the form to the other site? Without knowing that
    important question I can guess no more than : read from the socket.

    Comment

    • Erwin Moller

      #3
      Re: return value from cgi

      Paul Bearden wrote:
      [color=blue]
      > Greetings,
      >
      > I'm posting a form to a cgi application on another web site. The cgi
      > returns a text message to the browser. How can I capture this text message
      > and redirect based on the text.
      >
      > Example:
      > if (text == "SUCCESS")
      > http://www.good.com
      > else
      > http://fail.com
      >
      > Thanks![/color]


      Hi

      You cannot.
      If the client's webbrowser send a request to a cgi, the result is returned.
      Period.

      However, IF you are the one that is programming that CGI-script, you can let
      the script return a header with the new location, based on succes or
      failure or whatever.
      Like this:
      if($succes){
      header ("location: http://www.good.com");
      } else {
      header ("location: http://fail.com");
      }

      Regards,
      Erwin Moller

      Comment

      • Pedro Graca

        #4
        Re: return value from cgi

        Paul Bearden wrote:[color=blue]
        > I'm posting a form to a cgi application on another web site.[/color]

        How? How are you posting the form to the other web site?
        [color=blue]
        > The cgi returns
        > a text message to the browser. How can I capture this text message and
        > redirect based on the text.[/color]

        curl ( http://www.php.net/curl ) does it all!

        --
        Mail to my "From:" address is readable by all at http://www.dodgeit.com/
        == ** ## !! ------------------------------------------------ !! ## ** ==
        TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
        may bypass my spam filter. If it does, I may reply from another address!

        Comment

        • Paul Bearden

          #5
          Re: return value from cgi

          This is how the form is being posted:
          <form method="post"
          action="https://www.their_site. com/cgi-bin/their_applicati on.cgi">

          The cgi simply displays either succes or failure on the browser.
          Thanks!

          "Daniel Tryba" <spam@tryba.inv alid> wrote in message
          news:41d979d8$0 $6215$e4fe514c@ news.xs4all.nl. ..[color=blue]
          > Paul Bearden <paulbearden@sb cglobal.net> wrote:[color=green]
          >> I'm posting a form to a cgi application on another web site. The cgi
          >> returns
          >> a text message to the browser. How can I capture this text message and
          >> redirect based on the text.[/color]
          >
          > How are you posting the form to the other site? Without knowing that
          > important question I can guess no more than : read from the socket.
          >[/color]


          Comment

          • Daniel Tryba

            #6
            Re: return value from cgi

            Paul Bearden <paulbearden@sb cglobal.net> wrote:[color=blue]
            > This is how the form is being posted:
            > <form method="post"
            > action="https://www.their_site. com/cgi-bin/their_applicati on.cgi">
            >
            > The cgi simply displays either succes or failure on the browser.[/color]

            1) please don't TOFU, keep your posting readable.
            2) this is not what your question was about. In this situation a client
            sends the form directly to an other website, you can't get any results
            simply because your webserver never gets involved in the transaction.
            You'll need to send the form to your website and use somekind of
            httpclient (see phpclasses.org or PEAR_, CURL (http://nl2.php.net/curl)
            or simply how sockets and HTTP work, to construct a post to the other
            website and get the results.

            Comment

            • Erwin Moller

              #7
              Re: return value from cgi

              Pedro Graca wrote:
              [color=blue]
              > Paul Bearden wrote:[color=green]
              >> I'm posting a form to a cgi application on another web site.[/color]
              >
              > How? How are you posting the form to the other web site?
              >[color=green]
              >> The cgi returns
              >> a text message to the browser. How can I capture this text message and
              >> redirect based on the text.[/color]
              >
              > curl ( http://www.php.net/curl ) does it all!
              >[/color]

              Hi Pedro,

              But how to use curl when posting from a clients machine to another website?
              As Daniel pointed out in this thread: Your own server isn't involved!

              But both your responses give me the following idea:
              Server1 = your own server
              Server2 = another server (the one with failure or succes)
              Now:
              1) Let the forms action NOT be to Server2, but to Server2.
              2) Let Server2 (using curl) POST All the data to Server1.
              3) Now you can decide what to do on failure or succes.

              Maybe this was what you ment in the first place Pedro, in which case I'll
              bang my head with a fish.
              :-)

              Regards,
              Erwin Moller

              Comment

              • Pedro Graca

                #8
                Re: return value from cgi

                Erwin Moller wrote:[color=blue]
                > Pedro Graca wrote:[color=green]
                >> Paul Bearden wrote:[color=darkred]
                >>> The cgi returns
                >>> a text message to the browser. How can I capture this text message and
                >>> redirect based on the text.[/color][/color][/color]
                [color=blue][color=green]
                >> curl ( http://www.php.net/curl ) does it all![/color][/color]
                [color=blue]
                > But how to use curl when posting from a clients machine to another website?[/color]

                In that case I think you have no options :(
                [color=blue]
                > As Daniel pointed out in this thread: Your own server isn't involved![/color]

                I see that now.
                When you relinquish control to the foreign server all bets are off.
                [color=blue]
                > But both your responses give me the following idea:
                > Server1 = your own server
                > Server2 = another server (the one with failure or succes)
                > Now:
                > 1) Let the forms action NOT be to Server2, but to Server2.[/color]

                I take it you mean "let the form's action be to Server1"
                [color=blue]
                > 2) Let Server2 (using curl) POST All the data to Server1.[/color]

                Nope. The other way around.
                The clients posts to Server1, Server1 posts to Server2 and gets the
                result which is then sent to the client.
                [color=blue]
                > 3) Now you can decide what to do on failure or succes.[/color]

                Exactly :-)
                [color=blue]
                > Maybe this was what you ment in the first place Pedro, in which case I'll
                > bang my head with a fish.
                > :-)[/color]


                For example:

                You have a form which posts to "http://myserver.com/post.php".
                In post.php do something like this (not tested):

                <?php
                /* to whatevr you need to the $_POST array data and return
                * a new array with data in a proper format for foreignserver.c om
                */
                $new_data = deal_with_submi tted_data($_POS T);

                /* for example (suits me for the CURLOPT_POSTFIL EDS line below) */
                $new_data = array('user=nob ody', 'pwd=password', 'ref=1831958121 fcf0f91e02e5a7d 22e0079');

                $ch = curl_init();
                curl_setopt($ch , CURLOPT_URL, 'http://foreignserver.c om/post.cgi');
                curl_setopt($ch , CURLOPT_FOLLOWL OCATION, true);
                curl_setopt($ch , CURLOPT_POST, true);
                curl_setopt($ch , CURLOPT_POSTFIE LDS, implode('&', $new_data));
                curl_setopt($ch , CURLOPT_RETURNT RANSFER, true);

                /* get the response from foreignserver.c om */
                $feedback = curl_exec($ch);

                curl_close($ch) ;

                if (preg_match('fa iled', $feedback)) {
                echo '<p class="error">Y our post failed.</p>';
                } else {
                echo '<p class="success" >Your post was accepted.</p>';
                }
                ?>

                --
                Mail to my "From:" address is readable by all at http://www.dodgeit.com/
                == ** ## !! ------------------------------------------------ !! ## ** ==
                TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
                may bypass my spam filter. If it does, I may reply from another address!

                Comment

                • Erwin Moller

                  #9
                  Re: return value from cgi

                  Thanks for correcting my stupid typos Pedro.
                  :-)

                  Regards,
                  Erwin Moller

                  Comment

                  Working...