Php 我如何修复这个小小的oAuth';单头';错误?

Php 我如何修复这个小小的oAuth';单头';错误?,php,oauth,Php,Oauth,上下文:我有一个WordPress插件,允许用户通过Bitly进行身份验证,以便他们可以在需要时使用链接缩短功能 Bitly要求在应用程序设置中存储一个回调URL,因此我在服务器上创建了一个独立脚本来处理身份验证过程。整个握手过程实际上如下所示: 用户单击一个链接,将他们带到我的应用程序的Bitly授权页面 如果他们同意,他们将被转发到我的脚本中,并带有代码 我的脚本将该代码与Bitly交换另一个代码 一旦所有代码都被获取,它就会到达用户的域来存储代码,并在该用户的URL上检索选项页面的URL,

上下文:我有一个WordPress插件,允许用户通过Bitly进行身份验证,以便他们可以在需要时使用链接缩短功能

Bitly要求在应用程序设置中存储一个回调URL,因此我在服务器上创建了一个独立脚本来处理身份验证过程。整个握手过程实际上如下所示:

  • 用户单击一个链接,将他们带到我的应用程序的Bitly授权页面

  • 如果他们同意,他们将被转发到我的脚本中,并带有代码

  • 我的脚本将该代码与Bitly交换另一个代码

  • 一旦所有代码都被获取,它就会到达用户的域来存储代码,并在该用户的URL上检索选项页面的URL,这样我们就可以将用户重定向回主页

  • 然后,我们将用户重定向回他们刚刚单击过的选项页面

  • 问题:然而,只有极少数用户在身份验证过程完成之前出现以下错误:

    警告:标题不能包含多个标题,新行 在第72行的/home/warfarep/public_html/bitly_oauth.php中检测到

    示例代码:

    function sw_file_get_contents_curl($url){
        $ch=curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch, CURLOPT_FAILONERROR, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
        curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
        $cont = @curl_exec($ch);
        $curl_errno = curl_errno($ch);
        curl_close($ch);
        if ($curl_errno > 0) {
            return 0;
        }
        return $cont;
    }
    
    // Check if this is the first pass and we have the generic code
    if(isset($_GET['code'])):
    
        // Retreive the information
        $code               = $_GET['code'];
        $client_ID          = 'blahblahblah';
        $client_secret      = 'blahblahblah';
        $redirect_url       = 'blahblahblah';
        $state              = $_GET['state'];
    
        $url = 'https://api-ssl.bitly.com/oauth/access_token';
        $fields = array(
            'code'          => urlencode($code),
            'client_id'     => urlencode($client_ID),
            'client_secret' => urlencode($client_secret),
            'redirect_uri'  => urlencode($redirect_url),
            'state'         => urlencode($state)
        );
    
        //url-ify the data for the POST
        foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
        rtrim($fields_string, '&');
    
        //open connection
        $ch = curl_init();
    
        //set the url, number of POST vars, POST data
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_POST, count($fields));
        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_HTTPHEADER, array('Accept: application/json'));
    
        //execute post
        $response = curl_exec($ch);
    
        //close connection
        curl_close($ch);
    
        $response = json_decode($response , true);
    
        $ajax_url = $state .= '?action=sw_bitly_oauth&access_token='.$response['access_token'].'&login='.$response['login'];
    
        $wp_response = sw_file_get_contents_curl($ajax_url);
    
        $wp_response = rtrim($wp_response , '0');
    
        header('Location: '.$wp_response);
        ^^^^^^ This is line 72 from the error message
    
    endif;
    
    问题:在第72行重定向之前,您是否可以看到任何阻止发送头的内容?如何修复此位oauth“单头”错误?谢谢