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!