By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 2,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

return value from cgi

P: n/a
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!
Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Paul Bearden <pa*********@sbcglobal.net> wrote:
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.


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.

Jul 17 '05 #2

P: n/a
Paul Bearden wrote:
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!

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
Jul 17 '05 #3

P: n/a
Paul Bearden wrote:
I'm posting a form to a cgi application on another web site.
How? How are you posting the form to the other web site?
The cgi returns
a text message to the browser. How can I capture this text message and
redirect based on the text.


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!
Jul 17 '05 #4

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

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

"Daniel Tryba" <sp**@tryba.invalid> wrote in message
news:41**********************@news.xs4all.nl...
Paul Bearden <pa*********@sbcglobal.net> wrote:
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.


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.

Jul 17 '05 #5

P: n/a
Paul Bearden <pa*********@sbcglobal.net> wrote:
This is how the form is being posted:
<form method="post"
action="https://www.their_site.com/cgi-bin/their_application.cgi">

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


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.

Jul 17 '05 #6

P: n/a
Pedro Graca wrote:
Paul Bearden wrote:
I'm posting a form to a cgi application on another web site.


How? How are you posting the form to the other web site?
The cgi returns
a text message to the browser. How can I capture this text message and
redirect based on the text.


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


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
Jul 17 '05 #7

P: n/a
Erwin Moller wrote:
Pedro Graca wrote:
Paul Bearden wrote:
The cgi returns
a text message to the browser. How can I capture this text message and
redirect based on the text.
curl ( http://www.php.net/curl ) does it all!
But how to use curl when posting from a clients machine to another website?
In that case I think you have no options :(
As Daniel pointed out in this thread: Your own server isn't involved!
I see that now.
When you relinquish control to the foreign server all bets are off.
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.
I take it you mean "let the form's action be to Server1"
2) Let Server2 (using curl) POST All the data to Server1.
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.
3) Now you can decide what to do on failure or succes.
Exactly :-)
Maybe this was what you ment in the first place Pedro, in which case I'll
bang my head with a fish.
:-)

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.com
*/
$new_data = deal_with_submitted_data($_POST);

/* for example (suits me for the CURLOPT_POSTFILEDS line below) */
$new_data = array('user=nobody', 'pwd=password', 'ref=1831958121fcf0f91e02e5a7d22e0079');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://foreignserver.com/post.cgi');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $new_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

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

curl_close($ch);

if (preg_match('failed', $feedback)) {
echo '<p class="error">Your 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!
Jul 17 '05 #8

P: n/a
Thanks for correcting my stupid typos Pedro.
:-)

Regards,
Erwin Moller

Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.