WordPress结构化数据插件sitemap1.0问题不断啊!前面逍遥乐说了, 有效解决wordpress插件百度结构化数据——百度sitemap1.0一直校验中及sign检测失败的解决方法 接下来逍遥乐虽然是验证成功了,却遇到了新的问题!
发布文章或编辑文章时就会出现错误代码,如下图所示:文字为:
Warning: curl_setopt() [function.curl-setopt]: 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函数
具体代码如下:
//follow on location problems workaround
// modified by yanggg QQ 346767073
// 参数 gettype = 0 表示 读取的是 html内容,不包括head , type=1 表示读取 内容和head
function curl_redir_exec($ch, $gettype=0)
{
//echo 'curl_redir_exec............';
static $curl_loops = 0;
static $curl_max_loops = 20;
if ($curl_loops++>= $curl_max_loops)
{
$curl_loops = 0;
//echo '超出次数了';
return FALSE;
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
// 参数 gettype = 0 表示 读取的是 html内容,不包括head
$data = curl_exec($ch);
if($gettype === 0 ){
//echo $data;
//var_dump( explode("\n\n", $data, 2));
$data = str_replace("\r", "", $data);
//echo "------strpos ------:" .strpos($data, "\n\n");
//var_dump(explode("\n\n", $data,2));
$aa = explode("\n\n", $data,2);
//原版这里错了
//list($header, $data) = explode("\n\n", $data, 2);
$header = $aa[0];
$data = $aa[1];
//echo "---------header-------------:" . $header;
//echo "---------data-------------:" . $data;
}else{
//不用处理
}
$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)));
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);
return curl_redir_exec($ch);
} else {
$curl_loops=0;
return $data;
}
}
然后使用
curl_redir_exec($ch);替换512行的curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);语句
其他wrordpress的程序 调用
if (ini_get('open_basedir') == '' && strtolower(ini_get('safe_mode')) != 'on'){
curl_setopt($curl, CURLOPT_FOLLOWLOCATION,1);
$html = curl_exec($curl); // execute the curl command
}else{
$html = curl_redir_exec($curl);
}
以上教程参考至:
http://www.php.net/manual/en/function.curl-setopt.php