Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    extract url from xml response and redirect

    Hi,
    I submit form data as an xml string - $strXML - using curl:

    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
    curl_close($ch);

    The xml response is:

    <result>
    <posting_error>0</posting_error>
    <lead>0</lead>
    <valid>1</valid>
    <redirect_url>http://www.xxx.com</redirect_url>
    </result>

    and I need to redirect the user to <redirect_url>.

    I am trying the following:

    $xml = new SimpleXMLElement($strResult);
    header("Location:" . $xml->result->redirect_url);

    but with no joy.
    Could anyone suggest how I can achieve what I want?
    Thanks.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    This seems a bit of overkill:

    Code:
    $xml = new SimpleXMLElement($strResult);
    header("Location:" . $xml->result->redirect_url);
    Try, (untested):

    Code:
    preg_match('~\<redirect_url\>([^\<]+)\<\/redirect_url\>~', $strResult, $uri);
    print_r($uri);
    header('Location: '.$uri[1]);
    Remove or comment the print_r() line after testing.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •