2011-09-11 136 views
32

我遇到此错误。我不知道如何处理这个问题。无法修改标题信息 - 标题已发送... Wordpress问题

不能更改头信息 - 头已经(输出 开始在 /home/ben213/public_html/wp-content/themes/Bendaggers/functions.php:9) 发送到/ home/ben213 /的public_html /wp-includes/pluggable.php上线934

我functions.php文件行#9:

<?php if(function_exists('register_sidebar'))register_sidebar();?> 

而我pluggable.php#934

function wp_redirect($location, $status = 302) { 
    global $is_IIS; 

    $location = apply_filters('wp_redirect', $location, $status); 
    $status = apply_filters('wp_redirect_status', $status, $location); 

    if (!$location) // allows the wp_redirect filter to cancel a redirect 
     return false; 

    $location = wp_sanitize_redirect($location); 

    if (!$is_IIS && php_sapi_name() != 'cgi-fcgi') 
     status_header($status); // This causes problems on IIS and some FastCGI setups 

    header("Location: $location", true, $status);} 
endif; 
我有一个硬的时间,因为我不是一个程序员搞清楚了这一点

。什么似乎是错的? 好心帮我请...

+0

嗨保罗,美好的一天!对不起,请问您能用英文翻译一下吗?所以我该怎么做? –

+0

什么是'pluggable.php'?你为什么拥有它?它看起来应该包含在'functions.php'之前,因为它试图设置HTTP标头,并且在开始输出HTML之前需要设置它们。 –

+0

在这里不知道保罗,我知道的是<?php if(function_exists('register_sidebar'))register_sidebar();?>是用于widgetizing我的侧边栏。不知道,对不起。 –

回答

77

你的主题是打印输出(文本)的浏览器,但后来由于某种原因,WordPress是将用户重定向(与wp_redirect)从该网页离开整个页面呈现之前。你不能开始打印输出然后重定向,否则你会看到你看到的错误。这就是保罗格里姆在评论中所说的。

Ken White评论了对具有类似问题的帖子的引用。我通过缓冲脚本的输出来解决这个问题。

在你的主题functions.php文件(该文件被列入每一个你的主题的网页加载时间),把下面的:

//allow redirection, even if my theme starts to send output to the browser 
add_action('init', 'do_output_buffer'); 
function do_output_buffer() { 
     ob_start(); 
} 

现在,即使你的主题的一部分,开始输入发送到浏览器,PHP赢得在页面完全加载之前,不会发送该文本,这使WordPress可以根据需要重定向用户,作为其自身逻辑的一部分。

+1

谢谢。这解决了我的问题! – Phaedrus

+1

完美的作品! – Julien

+1

@BenDaggers请将此答案标记为正确,或对其原因进行评论。谢谢。 – hitautodestruct

18

如果您尝试将您的当前页面中的另一个页面重定向到您已施加条件或无条件的地方,请使用此代码。 E.gs你有两页A.php,& B.php和currenty你在A.php你想要去其他页面B.php点击按钮。

if(isset($_POST['save_btn'])) 
    { 
     //write some of your code here, if necessary 
     echo'<script> window.location="B.php"; </script> '; 
    } 
相关问题