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

curl过程中出现这样的错误:

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);
        
        // 封装请求函数
            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);  // 设置允许重定向
                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);  // 设置 Content-Type,默认 application/json
                curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, true);
        
                $response = curl_exec ($ch);
                curl_close ($ch);
        
                return $response;
        }

请教是什么原因?php.ini中需要设置?

阅读 4.2k
2 个回答

启用CURLOPT_FOLLOWLOCATION 的选项需要设置PHP.ini中的open_basedir选项,主要是安全问题。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏