无可否认,我是一个新手,只知道足够危险。
出于安全考虑,主机服务器不允许使用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);发布于 2012-04-27 02:34:48
您可以完全删除CURLOPT_POST...行。没有设置$request,在GET请求就可以的情况下,您不需要发出post请求。您可能需要也可能不需要使用CURLOPT_FOLLOWLOCATION --如果curl尚未按需工作,则将其打开。
https://stackoverflow.com/questions/10338877
复制相似问题