Use a PHP PROXY to bypass security issues in Flex/Flash
Reading RSS feeds from Flex or Flash often generate some security issues when the origin domain doesn’t contain a crossdomain.xml file to manage the policy settings.
A little workaround is create a PHP proxy to read the feeds and pass the content to the Flex script.
We’ll pass the ‘url’ variable from Flex and we’ll get the source avoiding security problems.
PHP code is very simple.
<?php readfile($_REQUEST["url"]); ?>
TIP: to use the readfile() php method you need to switch ON the allow_url_fopen PHP property on your apache webserver.
If you don’t know if this variable is enabled, use the phpInfo() function to get a list of your server settings.
In few words, instead to call the original xml feed
<mx:HTTPService id="loadXML" url="http://www.hwupgrade.it/rss_hwup.xml " ....
we’ll call the php script passing the url property
<mx:HTTPService id="loadXML" url="http://localhost/path/rssReader.php?url=http://www.hwupgrade..." ...
NOTE: We use the complete path with localhost because the php code needs to be compiled under an apache webserver to return a valid result.
You could also configure your Flex Project to automatically compile there.
Following the MXML source code:
<![CDATA[ import mx.rpc.events.ResultEvent; import mx.events.ListEvent; import mx.controls.Alert; /** * Dispatched after XML loading is completed */ private function resultHandler(event:ResultEvent):void { // List population listCompo.dataProvider = loadXML.lastResult.channel.item } ]]> <!--THIS CALL GENERATE A SECYURITY PROBLEM --> <!-- <mx:HTTPService id="loadXML" url="http://www.hwupgrade.it/rss_hwup.xml" useProxy="false" resultFormat="e4x" result="resultHandler(event)" fault="Alert.show('File XML with errors or not found' + loadXML.url + event.fault, 'error') " /> --> <!--THIS CALL USE A PROXY PHP TO AVOID Security Problems -->











Leave your response!