不可否认,我是新手,只知道危险。如何使用CURL而不是file_get_contents重写此RSS阅读器?
由于安全考虑,主机服务器不允许file_get_contents。我如何使用curl而不是file_get_contents来重写下面的代码?
这是一个jQuery手机网站上的RSS阅读器。该代码是基于一个教程,我发现在这里: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);
?>
编辑:将这项工作?
$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);
如果您的托管服务提供商不允许file_get_contents,他们肯定不会允许PHP cURL(它需要与PHP分开安装)。 – honyovk 2012-04-26 18:08:47
谢谢你的抬头。 – James 2012-04-26 18:23:20
您可能只需打开一个php.ini文件就可以打开file_get_contents(搜索您的提供商的详细信息) – 2012-04-26 18:28:55