2014-02-08 39 views
0

問題我主持的MEDIATEMPLE電網WordPress站點和我收到了,並試圖提交表單時的錯誤有關的open_basedir。提交時,表格會在新書中創建一個新客戶。安全模式關閉,所以我相當積極的問題是與open_basedir。我收到的錯誤是:CURLOPT_FOLLOWLOCATION和open_basedir的與MEDIATEMPLE電網

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /nfs/c04/h03/mnt/181950/domains/domain_dir/html/wp-content/plugins/gravityformsfreshbooks/api/HttpClient.php on line 79 

查看mediatemple文檔,他們建議將一行添加到php.ini文件中。他們的例子是:

open_basedir = "/path/to/first/folder:/path/to/second/folder" 

我去我的php.ini文件中還說:

open_basedir = "/home/domains/domain_dir/html/:/home/181950/data/tmp/" 

加入這一行後,問題不就解決了。將該行添加到我的php.ini文件後,我的網站不顯示。唯一出現的是這個錯誤:

Warning: require() [function.require]: open_basedir restriction in effect. File(/nfs/c04/h03/mnt/181950/domains/domain_dir/html/wp-blog-header.php) is not within the allowed path(s): (/home/domains/domain_dir/html/:/home/181950/data/tmp/) in /nfs/c04/h03/mnt/181950/domains/domain_dir/html/index.php on line 17 

回答

0

我遇到了同樣的問題。我做了一些手動遵循重定向的代碼。請確保您閱讀並理解代碼,並且在生產中使用它之前瞭解任何安全問題!

function remote_file($f){ 
    $i = 0; 
    do { 
     if($i++ > 10) die(); 
     //Pull the headers and check for redirects 
     $cr = curl_init($f); 
     curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, FALSE); 
     curl_setopt($cr, CURLOPT_RETURNTRANSFER, TRUE); 
     curl_setopt($cr, CURLOPT_BINARYTRANSFER, TRUE); 
     curl_setopt($cr, CURLOPT_HEADER, TRUE); 
     $curl_ret = curl_exec($cr); 
     //echo $curl_ret; 
     if(curl_getinfo($cr,CURLINFO_HTTP_CODE)!=200) { 
      $matches = preg_match_all('~location: ?(.*)~i',$curl_ret,$output); 
      if($matches) { 
       $f = $output[1][0]; 
      } 
     } else $matches = 0; 
    } while ($matches); 

    $cr = curl_init($f); 
    curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($cr, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($cr, CURLOPT_BINARYTRANSFER, TRUE); 
    //curl_setopt($cr, CURLOPT_FOLLOWLOCATION, TRUE); //Doesn't work with open_basedir retriction in effect 
    $curl_ret = curl_exec($cr); 

    curl_close($cr); 
    return $curl_ret; 
} 

編輯:在HttpClient.php,你應該有一個像

private function _init($url,$token) 
    { 
      $this->_url = $url; 
      $this->_token = $token; 
      //init connection 
      $this->_curlConn = curl_init($this->_url); 
      curl_setopt($this->_curlConn, CURLOPT_HEADER, false); 
      curl_setopt($this->_curlConn, CURLOPT_NOBODY, false); 
      curl_setopt($this->_curlConn, CURLOPT_RETURNTRANSFER, true); 
      curl_setopt($this->_curlConn, CURLOPT_FOLLOWLOCATION, true); 
      curl_setopt($this->_curlConn, CURLOPT_USERPWD, $this->_token); 
      curl_setopt($this->_curlConn, CURLOPT_TIMEOUT, 4); 
      curl_setopt($this->_curlConn, CURLOPT_SSL_VERIFYPEER, FALSE); // Validate SSL certificate 
      curl_setopt($this->_curlConn, CURLOPT_SSL_VERIFYHOST, FALSE); 
      curl_setopt($this->_curlConn, CURLOPT_USERAGENT, "FreshBooks API AJAX tester 1.0"); 
      return $this; 
    } 

功能你需要重寫這個功能,像

private function _init($url,$token) 
    { 
      $this->_url = $url; 
      $this->_token = $token; 
      //init connection 

      $i = 0; 
      do { 
       if($i++ > 10) die(); 
       //Pull the headers and check for redirects 
       $this->_curlConn = curl_init($this->_url); 
       curl_setopt($this->_curlConn, CURLOPT_SSL_VERIFYPEER, FALSE); 
       curl_setopt($this->_curlConn, CURLOPT_RETURNTRANSFER, TRUE); 
       curl_setopt($this->_curlConn, CURLOPT_BINARYTRANSFER, TRUE); 
       curl_setopt($this->_curlConn, CURLOPT_HEADER, TRUE); 
       curl_setopt($this->_curlConn, CURLOPT_USERPWD, $this->_token); 
       curl_setopt($this->_curlConn, CURLOPT_USERAGENT, "FreshBooks API AJAX tester 1.0"); 

       $curl_ret = curl_exec($cr); 
       //echo $curl_ret; 
       if(curl_getinfo($cr,CURLINFO_HTTP_CODE)!=200) { 
        $matches = preg_match_all('~location: ?(.*)~i',$curl_ret,$output); 
        if($matches) { 
         $this->_url = $output[1][0]; 
        } 
       } else $matches = 0; 
      } while ($matches); 

      $this->_curlConn = curl_init($this->_url); 
      curl_setopt($this->_curlConn, CURLOPT_HEADER, false); 
      curl_setopt($this->_curlConn, CURLOPT_NOBODY, false); 
      curl_setopt($this->_curlConn, CURLOPT_RETURNTRANSFER, true); 
      //curl_setopt($this->_curlConn, CURLOPT_FOLLOWLOCATION, true); 
      curl_setopt($this->_curlConn, CURLOPT_USERPWD, $this->_token); 
      curl_setopt($this->_curlConn, CURLOPT_TIMEOUT, 4); 
      curl_setopt($this->_curlConn, CURLOPT_SSL_VERIFYPEER, FALSE); // Validate SSL certificate 
      curl_setopt($this->_curlConn, CURLOPT_SSL_VERIFYHOST, FALSE); 
      curl_setopt($this->_curlConn, CURLOPT_USERAGENT, "FreshBooks API AJAX tester 1.0"); 
      return $this; 
    } 

這將有效地保持發送請求到他們的API,直到它返回一些不是重定向的東西。當它很高興時,它會將該重定向後的URL傳遞給標準代碼,該標準代碼會將其選中並繼續。

哦,其他的事情我纔去這方面的努力嘗試...如果你只是註釋掉HttpClient.php違規行?它實際上是否需要遵循任何重定向?

+0

感謝您的幫助!我其實仍然有同樣的問題。是否有需要添加該功能的特定文件?我將它添加到我的functions.php文件和HttpClient.php文件中。 – user715564

+0

這應該做到!所有你應該做的就是彈出它在你的functions.php(或其他),然後改變HttpClient.php ..我將編碼到我的答案 – SpoonNZ

相關問題