解决WordPress结构化数据插件发布文章Warning: curl_setopt() [function.curl-setopt]错误

sitemap1.0问题不断啊!前面逍遥乐说了,有效解决wordpress插件百度结构化数据——百度sitemap1.0一直校验中及sign检测失败的解决方法 接下来逍遥乐虽然是验证成功了,却遇到了新的问题!

或编辑文章时就会出现错误代码,如下图所示:解决WordPress结构化数据插件发布文章Warning: curl_setopt() [function.curl-setopt]错误文字为:

Warning: : CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /*****/wp-content/plugins/baidusubmit/inc/sitemap.php on line 521

Warning: Cannot modify header information - headers already sent by (output started at /*****/wp-content/plugins/baidusubmit/inc/sitemap.php:521) in /*****/wp-includes/pluggable.php on line 896

解决:

碰到此问题解决办法参考下面方法

当系统开启safe_mode和 open_basedir,在程序中使用以下语句

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);

 

并且遇到301,302状态码时会出现错误

[11-Oct-2010 14:17:41] PHP Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in msn.class.php on line 819

解决方法是在curl语句用不使用curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true),在php函数中自定义一个curl_redir_exec函数

具体代码如下:

function curl_redir_exec($ch,$debug="") 
{ 
    static $curl_loops = 0; 
    static $curl_max_loops = 20; 

    if ($curl_loops++ >= $curl_max_loops) 
    { 
        $curl_loops = 0; 
        return FALSE; 
    } 
    curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $data = curl_exec($ch); 
    $debbbb = $data; 
    list($header, $data) = explode("\n\n", $data, 2); 
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 

    if ($http_code == 301 || $http_code == 302) { 
        $matches = array(); 
        preg_match('/Location:(.*?)\n/', $header, $matches); 
        $url = @parse_url(trim(array_pop($matches))); 
        //print_r($url); 
        if (!$url) 
        { 
            //couldn't process the url to redirect to 
            $curl_loops = 0; 
            return $data; 
        } 
        $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); 
    /*    if (!$url['scheme']) 
            $url['scheme'] = $last_url['scheme']; 
        if (!$url['host']) 
            $url['host'] = $last_url['host']; 
        if (!$url['path']) 
            $url['path'] = $last_url['path'];*/ 
        $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:''); 
        curl_setopt($ch, CURLOPT_URL, $new_url); 
    //    debug('Redirecting to', $new_url); 

        return curl_redir_exec($ch); 
    } else { 
        $curl_loops=0; 
        return $debbbb; 
    } 
}

然后使用

curl_redir_exec($ch);替换512行的curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);语句

以上教程参考至:
http://www.php.net/manual/en/function.curl-setopt.php