I was adding my digg feeds to my RSS reader I wrote in PHP and noticed file_get_contents wouldn't let me connect to the RSS feed. Turns out they want to be tricked and have you set the user agent. So if you need to get RSS feeds working with PHP, just use ini_set and the user agent and you should be just dandy.


// sites like digg like to be tricked
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6');

/*---------------------------------------------------------------------------------------*/
// grab the contents of the rss feed
$rss_file = file_get_contents($url);

// load up our simple xml object
if(!$feed = simplexml_load_string($rss_file))
{
die("Cannot load RSS Feed.");
}

Ready for More?

Follow Me @jimplush