PHP proxy to get XML: problem with URL arguments -


so need retrieve xml public api, app in flash , public service won't implement crossdomain.xml file. found php script online (below) proxy request url. works fine urls like:

http://mysite.com/xml_proxy.php?url=http://rss.cnn.com/rss/cnn_topstories.rss

but script seems either strip or ignore arguments on url, like:

http://mysite.com/xml_proxy.php?url=http://publicapiserver.com?app_id=35235x&app_key=84x

i'm php ignorant. there easy way have script process url arguments? much. here script:

<?php  $post_data = $http_raw_post_data;  $header[] = "content-type: text/xml"; $header[] = "content-length: ".strlen($post_data);  $ch = curl_init( $_get['url'] );  curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_timeout, 10); curl_setopt($ch, curlopt_httpheader, $header);  if ( strlen($post_data)>0 ){     curl_setopt($ch, curlopt_post, 1);     curl_setopt($ch, curlopt_postfields, $post_data); }  $response = curl_exec($ch);      $response_headers = curl_getinfo($ch);       if (curl_errno($ch)) {     print curl_error($ch); } else {     curl_close($ch);     header( 'content-type: ' . $response_headers['content-type']);     print $response; } ?> 

if want url through script unscathed url parameter, you'll have url-encode first, @ flash side. example, correct url use script example actually:

http://mysite.com/xml_proxy.php?url=http%3a%2f%2fpublicapiserver.com%3fapp_id%3d35235x%26app_key%3d84x 

otherwise web server , php confused bit of url url proxy service, , bit url want go data from.

the solution flash side depends on how you're doing call @ moment. actionscript has escape() function encoding you. want encode url you're sending proxy, not url of proxy itself, leave proxy url ("http://mysite.com/xml_proxy.php?url=") , throw escape()'d url of site want data on end of it.

you don't need php end, because php automatically url-decodes parameters in $_get variable, how you're grabbing url in php code.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -