設置當運行該腳本(http://bizonbytes.com/miscellaneous/sharrre.php?url=https://bizonbytes.com &類型= GOOGLEPLUS ):CURLOPT_FOLLOWLOCATION不能當啓用safe_mode設置或激活了open_basedir在
<?php
//Sharrre by Julien Hany
$json = array('url'=>'','count'=>0);
$json['url'] = $_GET['url'];
$url = urlencode($_GET['url']);
$type = urlencode($_GET['type']);
if(filter_var($_GET['url'], FILTER_VALIDATE_URL)){
if($type == 'googlePlus'){ //source http://www.helmutgranda.com/2011/11/01/get-a-url-google-count-via-php/
$content = parse("https://plusone.google.com/u/0/_/+1/fastbutton?url=".$url."&count=true");
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
@$dom->loadHTML($content);
$domxpath = new DOMXPath($dom);
$newDom = new DOMDocument;
$newDom->formatOutput = true;
$filtered = $domxpath->query("//div[@id='aggregateCount']");
$json['count'] = str_replace('>', '', $filtered->item(0)->nodeValue);
}
else if($type == 'stumbleupon'){
$content = parse("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=$url");
$result = json_decode($content);
$json['count'] = $result->result->views;
if(!isset($json['count'])) $json['count'] = 0;
}
else if($type == 'pinterest'){
$content = parse("http://api.pinterest.com/v1/urls/count.json?callback=&url=$url");
$result = json_decode(str_replace(array('(', ')'), array('', ''), $content));
$json['count'] = $result->count;
if(!isset($json['count'])) $json['count'] = 0;
}
}
echo str_replace('\\/','/',json_encode($json));
function parse($encUrl){
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => 'sharrre', // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 5, // timeout on connect
CURLOPT_TIMEOUT => 10, // timeout on response
CURLOPT_MAXREDIRS => 3, // stop after 10 redirects
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => false,
);
$ch = curl_init();
$options[CURLOPT_URL] = $encUrl;
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
curl_close($ch);
if ($errmsg != '' || $err != '') {
/*print_r($errmsg);
print_r($errmsg);*/
}
return $content;
}
?>
我得到以下錯誤:
Warning: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in C:\Inetpub\vhosts\bizonbytes.com\httpdocs\miscellaneous\sharrre.php on line 56
{"url":"https://bizonbytes.com","count":""}
重要事項
- 我有PHP沒有經驗。我只需要運行該腳本 (sharrre.php)
- 我已經看看其他類似的情況,但可以找出問題。
- 我打開窗戶/ php.ini並確信safe_mode設置=關
- 我注意的open_basedir設置是這樣;的open_basedir =
- 我需要在添加的open_basedir的東西?
- 這是關於安裝的PHP版本的詳細信息的鏈接。見http://bizonbytes.com/miscellaneous/test.php
謝謝大家對你的幫助,在此問題上
PHP可以有多個.ini文件和在該INI型覆蓋可以進行各種級別。在你的腳本中的某個地方運行'phpinfo()'來查看實際的本地效果設置是什麼。 –
@MarcB當你運行http://bizonbytes.com/miscellaneous/test.php你會得到我認爲的信息。 – Yannick