How to extract the response string from php after posting data to an external server using the html publishing form?


How extract php response query string after posting data to external server using html post form?


<form name="form2" method="post" action="" id="form1">
    <input type="hidden" value="<?php echo $amt;?>" name="amt" />
    <input type="hidden" name="merchant" value="abc">
    <input type="hidden" name="orderid" value="<?php echo $orderid;?>">
    <input type="hidden" name="referenceid" value="<?php echo  $referenceid;?>">
    <input type="submit" value="submit"/>

I think the outcome is xml as the developer guide shows




How to get the response ? Please show in code. can the response code be in the delivery.php?

IF you want to handle the response to a post to a remote server you have to perform the post on the server side, not by the client (browser).

So something like this would be the idea:

client --POST--> your server --response--> client
                  |      ^
                 POST    |
                  |   response
                  V      |
                remote server

So you show a page to the user where he can fill in the required data then post it to a form handler page on your server. That handler page can make the request to the remote server and parsing the response it can generate the appropriate answer to the client.

You can use CURL for example to make the remote request on the server side.

An example would be something like this: (CURL example based on an other SO answer)

if (empty($_POST['amt'])) {
  // show form
} else {
    $data = ...; // collect and filter data from form

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,"");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

    // receive server response ...
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $server_output = curl_exec ($ch);

    curl_close ($ch);

    // further processing ....
    if ($server_output == "OK") {
        // parse $server_output
        $message = 'success';
    } else {
        $message = 'error';

    // show $message to user

This example by no means complete but hopefully gives you an idea.