-2

I have a PHP form that sends to an external web script that then displays XML response, that I need to instead, capture the response and parse it on my PHP script.

I know I need to direct to itself, but I don't know how to capture the response from the external web url to get the XML data.

Using <form method="POST" action="http://example.net/webaction.php"> , the webaction.php script will return XML data.

Now I need to change <form methond="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> and then capture the XML from http://example.net/webaction.php output.

UPDATE: The output of http://example.net/webaction.php script looks like this and will not be saved or collected, it only returns a status response to the form data submitted.

<datacheck>
<script/>
<webresults>
    <formdata1>167917</formdata1>
    <formdata2>20190101</formdata2>
    <formdata3>10</formdata3>
    <results>
        <code>ACTIVE ( ACT19 )</code>
        <description>
            This product is verified.
        </description>
        <brandinfo>
            ACME Company New York New York
        </brandinfo>
    </results>
</webresults>

With these results above, I need to display it on my php page in user-friendly manner once I can get these results.

Any guidance or direction will be greatly appreciated!!

Thanks!

bash3r
  • 123
  • 1
  • 6

2 Answers2

0

If I understand correctly what you need is some kind of proxy. If so, something like this might do it:

foreach($_REQUEST as $a=>$b)
    {
    $res[]=$a.'='.$b;
    }
echo file_get_contents('http://google.com?'.join('&',$res));

If you need the POST method instead please check How to post data in PHP using file_get_contents?

Radacina
  • 431
  • 5
  • 10
0

A small example could help you here, using isset on the $_POST['submit'] parameter from the submit button and file_get_contents you can get the output of the PHP-File when the form was submitted. I really hope thats what you searched for!

<?php
    if (isset($_POST['submit'])) {
        echo file_get_contents('http://example.net/webaction.php');
    }
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <button name="submit" submit>submit</button>
</form>
Updater
  • 459
  • 2
  • 13