鍍金池/ 問答/PHP  Linux/ php中curl出錯 Warning: curl_setopt(),求教什么原因

php中curl出錯 Warning: curl_setopt(),求教什么原因?

curl過程中出現(xiàn)這樣的錯誤:

Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set in H:\htdocs\minapp\token.php on line 31 

代碼:

    <?php
            ini_set('display_errors', true);
            error_reporting(E_ALL);
            $param = [
                'client_id'     => "xxxxxxba31",
                'client_secret' => "xxxxx02bcda1c6a9e",
            ];
        // 獲取 code
            $code_url  = 'https://xxx.a.com/';
            $code_data = postData ($code_url, json_encode ($param));
        
            $code_data = json_decode ($code_data, true);// 使用 code 獲取 Access Token
        
        // echo $code_data;
            $param['code']       = $code_data['code'];
            $param['grant_type'] = 'authorization_code';
        
            $access_token_url = 'https://xxx.a.com/api/';
            $access_token     = postData ($access_token_url, $param, 'multipart/form-data'); // 獲取到的 Access Token
                print_r ($access_token);
        
        // 封裝請求函數(shù)
            function postData($url, $param, $content_type = 'application/json')
            {
                $ch = curl_init ();
        
                curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
                curl_setopt ($ch, CURLOPT_URL, $url);
                curl_setopt ($ch, CURLOPT_POST, true);
                curl_setopt ($ch, CURLOPT_POSTFIELDS, $param);
   31行         curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);  // 設(shè)置允許重定向
                curl_setopt ($ch, CURLOPT_AUTOREFERER, 1);
                curl_setopt ($ch, CURLOPT_COOKIEFILE, '');
                curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt ($ch, CURLOPT_COOKIESESSION, true);
                curl_setopt ($ch, CURLINFO_CONTENT_TYPE, $content_type);  // 設(shè)置 Content-Type,默認(rèn) application/json
                curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, true);
        
                $response = curl_exec ($ch);
                curl_close ($ch);
        
                return $response;
        }

請教是什么原因?php.ini中需要設(shè)置?

回答
編輯回答
解夏

啟用CURLOPT_FOLLOWLOCATION 的選項需要設(shè)置PHP.ini中的open_basedir選項,主要是安全問題。

2017年4月28日 00:04
編輯回答
孤慣

善用百度

解決方案有兩個,一個是重新寫follow,一個是關(guān)閉follow,這里都有

http://www.php.net/manual/en/...

2018年5月14日 08:55