473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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")
http://www.good.com
else
http://fail.com

Thanks!
Jul 17 '05 #1
8 2313
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
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
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
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
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
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
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
Thanks for correcting my stupid typos Pedro.
:-)

Regards,
Erwin Moller

Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Neal Coombes | last post by:
Posted to comp.lang.c++.moderated with little response. Hoping for better from the unmoderated groups: -------- Original Message -------- Subject: Return appropriately by value, (smart)...
16
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
12
by: Michael Maes | last post by:
Hello, I have a BaseClass and many Classes which all inherit (directly) from the BaseClass. One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk. ...
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
6
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document...
7
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function...
6
KoreyAusTex
by: KoreyAusTex | last post by:
If anyone can help me figure out the what the missing return statements are, I think it might be the fact that I need to add a return false in the getValue()? import java.util.*; public class...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.