诚然,我是个新手,只知道危险。
出于安全考虑,主机服务器不允许使用 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);