CURL returns XML or JSON

I have a form here - http://example.com/palreg.php

As soon as people register, I will send them an email with a link that will allow them to edit their data (I know that this is a crazy way to do something, but I work on the code of another, so do not mind) for example url as such http://example.com/palreg.php?paliD=1234, and when they will go to this page, the form will be filled with their information so that they can make changes.

Now the problem is that the database is on another site, and the information must be passed to this site to perform the select action, for this I use cURL to send such information.

$url = "http://example2.com/processXML.php";
$xmlStr will be like this

<table>tab_name</table>
<action>select</action>
<palid>1234</palid>

$ch=curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'xmlstr='.$xmlStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);

(http://example2.com/processXML.php) xml , id .

, ( xml json array), .

return $dataArray; processXML.php ?

, , processXML.php

print json_encode($resultArray);

, , .

+3
3

, , . $data = -. JSON, .

//Bunch of DB stuff..
$row=mysql_fetch_however_you_handle_it();
echo json_encode($row);


//on your receiving end, that just did the cURL send,
$row=json_decode($data,true);//decode the JSON straight into an array...
+5

processXML.php, , json_encode() JSON, .

+1

Just highlight the data that you need to send back to the form in your selection format and select this answer in thepalreg.php file.

+1
source

Source: https://habr.com/ru/post/1786176/


All Articles