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中需要设置?
善用百度
解决方案有两个,一个是重新写follow,一个是关闭follow,这里都有
http://www.php.net/manual/en/...