Using a XHTTP proxy to access XML content from other sites

I came across this howto that details how you can Use a Web Proxy for Cross-Domain XMLHttpRequest Calls (read this link for good background info). This sounded intriguing so I had a play around and threw together this demonstration that uses this technique to fetch the latest technology news items from the BBC and display them on your web page.

There is one requirement and that is that the web page that makes the call (xhttp.html in my case) must live on the same web server as the xhttp proxy. Other than that you’re away laughing.

Check it out here – XHTTP Proxy Demonstration – Cross Domain XMLHttpRequest calls.

View the source of the page for comments – the server part is simply:

<?php// XmlHTTPRequest Web Proxy// Inspired by http://developer.yahoo.com/javascript/howto-proxy.html// Bob Brown, 2007-10-03 23:46

// Restrict this proxy to bbc.co.uk feeds onlyif (!preg_match('/\.bbc\.co\.uk\/.*rss\.xml$/',$_GET['url'])) {  $error = '403 Proxy Request Denied - URL not allowed';  header('HTTP/1.1 '.$error);  echo $error;}else{  header('Content-type: text/xml');  echo file_get_contents($_GET['url']);}?>

I think it might give unusual results in Internet Explorer – I don’t mind if you find and fix the bug, IE7 has never worked on my Vista install! Might have a look if I get bored.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

WordPress Themes