Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-25-2010, 04:18 PM   PM User | #1
free man
New to the CF scene

 
Join Date: Nov 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
free man is an unknown quantity at this point
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.
free man is offline   Reply With Quote
Old 11-25-2010, 05:30 PM   PM User | #2
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
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.
MattF is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:34 PM.


Advertisement
Log in to turn off these ads.