2014-02-10 94 views
11

運行腳本時出現以下錯誤。該錯誤消息是如下...服務器配置allow_url_fopen = 0

警告:file_get_contents()函數[function.file-GET-內容]:https://開頭包裝紙在服務器配置中禁用於allow_url_fopen = 0 /家/ satoship /public_html/connect.php on line 22

我知道這是一個服務器問題,但爲了擺脫上述警告我需要做些什麼來服務器?

+6

變化的php.ini 'allow_url_fopen = on'; p –

+0

我已經完成了這個工作,但還沒有解決問題。我有權訪問服務器,但我不知道該怎麼做才能打開它 – JohnThomas

+1

不要忘記重新啓動apache'sudo service apache2 restart' –

回答

12

如果你沒有修改php.ini文件的能力,使用捲曲: PHP Curl And Cookies

這裏是一個例如功能我創建:

function get_web_page($url, $cookiesIn = ''){ 
     $options = array(
      CURLOPT_RETURNTRANSFER => true,  // return web page 
      CURLOPT_HEADER   => true,  //return headers in addition to content 
      CURLOPT_FOLLOWLOCATION => true,  // follow redirects 
      CURLOPT_ENCODING  => "",  // handle all encodings 
      CURLOPT_AUTOREFERER => true,  // set referer on redirect 
      CURLOPT_CONNECTTIMEOUT => 120,  // timeout on connect 
      CURLOPT_TIMEOUT  => 120,  // timeout on response 
      CURLOPT_MAXREDIRS  => 10,  // stop after 10 redirects 
      CURLINFO_HEADER_OUT => true, 
      CURLOPT_SSL_VERIFYPEER => true,  // Validate SSL Cert 
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
      CURLOPT_COOKIE   => $cookiesIn 
     ); 

     $ch  = curl_init($url); 
     curl_setopt_array($ch, $options); 
     $rough_content = curl_exec($ch); 
     $err  = curl_errno($ch); 
     $errmsg = curl_error($ch); 
     $header = curl_getinfo($ch); 
     curl_close($ch); 

     $header_content = substr($rough_content, 0, $header['header_size']); 
     $body_content = trim(str_replace($header_content, '', $rough_content)); 
     $pattern = "#Set-Cookie:\\s+(?<cookie>[^=]+=[^;]+)#m"; 
     preg_match_all($pattern, $header_content, $matches); 
     $cookiesOut = implode("; ", $matches['cookie']); 

     $header['errno'] = $err; 
     $header['errmsg'] = $errmsg; 
     $header['headers'] = $header_content; 
     $header['content'] = $body_content; 
     $header['cookies'] = $cookiesOut; 
    return $header; 
} 

注:在重新審視這個功能我注意到,我在此代碼禁用SSL檢查。即使在我的特定情況下,我使用的站點本地且安全,但這通常是一件糟糕的事情。因此,我修改了此代碼以默認進行SSL檢查。如果由於某種原因你需要改變它,你可以簡單地更新CURLOPT_SSL_VERIFYPEER的值,但是如果有人使用它,我希望代碼在默認情況下是安全的。

4

編輯php.ini,找到了allow_url_fopen並將其設置於allow_url_fopen = 1

+0

Homse主機因xss而禁用它。蝙蝠的建議。 – user1954544

17

@blytung有一個很好的功能,以取代功能

<?php 
$url = "http://www.example.org/"; 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
$contents = curl_exec($ch); 
if (curl_errno($ch)) { 
    echo curl_error($ch); 
    echo "\n<br />"; 
    $contents = ''; 
} else { 
    curl_close($ch); 
} 

if (!is_string($contents) || !strlen($contents)) { 
echo "Failed to get contents."; 
$contents = ''; 
} 

echo $contents; 
?>  
7

使用此代碼在您的PHP腳本(第一行)

ini_set('allow_url_fopen',1); 
+1

我在我的根目錄(public_html)中創建了一個空的php.ini文件,它的工作原理是:) – Ahmad

+3

此工作適用於4.3.4或更早版本。 4.3.4後''allow_url_fopen'必須在php.ini中註冊 http://php.net/manual/en/ini.list.php –

-2

這是一個非常簡單的問題

這是解決此問題的最佳方法。

步驟1:登錄到您的cPanel(http://website.com/cpanelhttp://cpanel.website.com)。

步驟2:軟件 - >選擇PHP版本

第3步:改變當前的PHP版本:5.6

第3步:HIT '設置爲當前'[ENJOY]