Admittedly, I’m a novice and know only enough to be dangerous.
The host server doesn’t allow file_get_contents due to security concerns. How can I rewrite the code below using curl instead of file_get_contents?
This is for a rss reader on a jquery mobile site. The code is based on a tutorial I found here: nets.tutplus.com/rssreader
<?php
$siteName = empty($_GET['siteName']) ? 'Website' : $_GET['siteName'];
$siteList = array(
'Website2',
'Website3',
'Website4',
'Website5',
'Website6',
);
// For security.
if ( !in_array($siteName, $siteList) ) {
$siteName = 'Website';
}
$location = "http://query.yahooapis.com/v1/public/yql?q=";
$location .= urlencode("SELECT * FROM feed where url='http://feeds.feedburner.com/$siteName'");
$location .= "&format=json";
$rss = file_get_contents($location, true);
$rss = json_decode($rss);
?>
Edit: Would this work?
$location = "http://query.yahooapis.com/v1/public/yql?q=";
$location .= urlencode("SELECT * FROM feed where url='http://feeds.feedburner.com/$siteName'");
$location .= "&format=json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, trim($request));
$rss = curl_exec($ch);
curl_close($ch);
$rss = json_decode($rss);
You can remove the
CURLOPT_POST...lines entirely.$requestis not set, and you don’t need to make a post request in this instance where a GET request will do. You may or may not need to useCURLOPT_FOLLOWLOCATION— turn it on if curl doesn’t already work as needed.