2
votes

I'm using curl to post form data in xml string. The xml response is <redirect_url>www.xxxxx.com</redirect_url>. Could anyone help me to extract this url and redirect the user to it? Thanks.

Sorry been away... Thanks for the responses. The code is:

// create a new cURL resource

$ch = curl_init('http://www.zzz.com/');

// set r appropriate options

$strXML = "<lead>   <applicant>   <title>".$title."</title>   <fname>".$fname."</fname>   <lname>".$lname."</lname>   <email>".$email."</email>   <dob>".$dob."</dob>   </lead>";

echo $strXML;

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, '1'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, array('lead'=>$strXML)); $strResult = curl_exec($ch); // close cURL resource, and free up system resources

echo $strResult;

curl_close($ch);

Example Response:

<result>
<posting_error>0</posting_error>
<valid_partner>1</valid_partner>
<redirect_url>www.xxx.com</redirect_url>
</result>
1
That doesn't look like XML to me. Could you show your code and the full response?Mike Caron
The website you put as example is actually a nudity website!ENSATE

1 Answers

4
votes

Use SimpleXML and header:

$xml = new SimpleXMLElement($xml_response);

header('Location: ' . $xml->redirect_url);