Forum Moderators: coopster

Message Too Old, No Replies

HTTP connection and Server response

Pls how do i extract the response from the server and redirect ...

         

dewteks

11:16 am on Jan 22, 2009 (gmt 0)

10+ Year Member



I have tried hard to connect to an SMS api using HTTP but couldnt make it work the way i wanted.

I have a form to be submited using POST method to a url: http://xx.#*$!.#*$!.xx/bulk/

if the operation is successful, the server responds with :
status=n&credit=mm&recipient=yyyyy&deterer=gggin the body of a page

The issues i have are:
1. how do i save the content of the form elements before posting them to the url
2. on posting the form directly to the url, it returns the response above in the body of a page pointing to the server.

Pls how do i extract the variables i need from the body of the server response page and redirect the response to my own custome page. cos i just need users to be redirected to a custome page showing just the status(i.e n) and credit( i.e mm) and recipients(i.e yyyyy)from the server.

Pls any help will be appreciated as i have tried several stuffs and read various articles from google and have not being able to achieve my objectives

whoisgregg

11:59 pm on Jan 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have the form point to a script on your server, you could use curl [php.net] to POST to the remote URL. Then your script can use parse_str [php.net] to turn that query string into an array. Something like this:

$ch = curl_init();
$data = array(
'name' => $_POST['name'],
'email' => $_POST['email'],
// etc. you get the idea ;)
);
curl_setopt($ch, CURLOPT_URL, 'http://remotehost/form.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($ch);
if($return === false){
echo 'Sorry! It didn\'t work.';
} else {
$result = parse_str($return);
print_r($result); // for debugging
echo 'Your status is '.$result['status'].' and your credit is '.$result['credit'].'.';
}