2012-02-10 66 views
2

我想問一些問題。
我有一個web服務器(apache2/php/debian),並且出於安全原因使用open_basedir選項配置了PHP。
我需要訪問URL使用file_get_contents(),但我得到錯誤警告:file_get_contents():open_basedir限制的效果。
我檢查了PHP配置並且allow_url_fopen已打開。

在開發服務器(ubuntu 10.10)中它可以正常工作,但在debian(6.0擠壓)中它沒有。任何想法 ??

PHP版是5.3.3-7 + squeeze7用了Suhosin貼片
一個例子:
PHP的Open_basedir對URL的限制

的php.ini:

Open_basedir = /var/securedir/:/var/www 
allow_url_fopen = On 

PHP代碼:

$a = file_get_contents("http://www.php.net"); 
Warning: file_get_contents(): open_basedir restriction in effect. 

另一個問題是:

$b = file_get_contents("/var/securedir/file.xml") 
Warning: file_get_contents(): open_basedir restriction in effect. File(/var/securedir/file.xml) is not within the allowed path(s): (/var/securedir/:/var/www) 
+1

你能舉個例子嗎? – 2012-02-10 11:26:04

+0

PHP的什麼版本?可能是https://bugs.php.net/bug.php?id=48603 – symcbean 2012-02-10 11:33:06

+0

PHP版本是5.3.3-7 + squeeze7 Suhosin-Patch – EsteveBlanch 2012-02-10 11:41:40

回答

0

爲什麼不使用cURL來獲取內容呢?它只是將是代碼一些額外的線路:

function fetch_content($sUrl) { 

    $aOptions = array(
     CURLOPT_RETURNTRANSFER => true, 
     CURLOPT_HEADER   => false 
    ); 

    $cUrlHndl = curl_init($sUrl); 
    curl_setopt_array($cUrlHndl, $aOptions); 
    $binaryContents = curl_exec($cUrlHndl); 
    curl_close($cUrlHndl); 

    return $binaryContents; 
} 

因爲你的file_get_contents造成安全隱患,這就是爲什麼它在服務器上禁用。您收到的警告是因爲您嘗試打開的路徑未包含在php.ini設置文件中。

相關問題