无法在Wordpress中修改标头信息错误

时间:2012-09-23 10:48:42

标签: php wordpress http-headers configuration-files pluggable

尝试登录管理面板时,我遇到了这个错误。我无法理解它。

Warning: Cannot modify header information - headers already sent by (output started at /home/xxxxxx/public_html/wordpress/wp-config.php:1) in /home/xxxxxx/public_html/wordpress/wp-includes/pluggable.php on line 881

pluggable.php 881:

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;

我使用的是最新版本的wordpress 3.4.2。我的网站似乎工作正常,但错误阻止我进入登录页面,这意味着我根本无法管理或卸载插件(dbc备份2)似乎已触发此问题。我已经使用HTML-kit工具检查了wp.config文件,并且在文件的开头和结尾都没有可见的空格。我有:

  1. 使用HTML-Kit工具检查wp-config文件中的空格
  2. 已下载并插入新的新wp-config文件
  3. 通过重命名禁用插件目录
  4. ......错误仍然存​​在

    我唯一要尝试的是这个代码,有人发布在wordpress论坛上声称他已经通过将以下代码插入wp-config.php文件解决了这个问题:

        <?
    //dont use header function in wordpress-wp_signup.php
    global $domain;
    global $path;
    //change urlnew variable as per requirment
    $urlnew = "http://".$domain.$path."/wp-admin/admin.php;
    
    echo "<script>";
    echo "location = '$urlnew';";
    echo "</script>";
    echo $urlnew;
    ?>
    

    我不愿意添加代码,因为我不熟悉html或php而且我并不完全理解这段代码的功能,也没有详细说明如何准确放置它。还有更好的建议吗?


    主题function.php文件以这样结束,我应该在哪里准确插入代码?:

    // include custom widget
    
    $temp_root = get_root_directory('include/plugin/custom-widget/custom-blog-widget.php');
    
    include_once($temp_root . 'include/plugin/custom-widget/custom-blog-widget.php'); 
    
    $temp_root = get_root_directory('include/plugin/custom-widget/custom-port-widget.php');
    
    include_once($temp_root . 'include/plugin/custom-widget/custom-port-widget.php'); 
    
    $temp_root = get_root_directory('include/plugin/custom-widget/custom-port-widget-2.php');
    
    include_once($temp_root . 'include/plugin/custom-widget/custom-port-widget-2.php'); 
    
    $temp_root = get_root_directory('include/plugin/custom-widget/popular-post-widget.php');
    
    include_once($temp_root . 'include/plugin/custom-widget/popular-post-widget.php'); 
    
    $temp_root = get_root_directory('include/plugin/custom-widget/contact-widget.php');
    
    include_once($temp_root . 'include/plugin/custom-widget/contact-widget.php'); 
    
    $temp_root = get_root_directory('include/plugin/custom-widget/flickr-widget.php');
    
    include_once($temp_root . 'include/plugin/custom-widget/flickr-widget.php'); 
    
    $temp_root = get_root_directory('include/plugin/custom-widget/twitter-widget.php');
    
    include_once($temp_root . 'include/plugin/custom-widget/twitter-widget.php');
    
    
    
    // get the path for the file ( to support child theme )
    
    function get_root_directory( $path ){
    
        if( file_exists( STYLESHEETPATH . '/' . $path ) ){
    
            return STYLESHEETPATH . '/';
    
        }else{
    
            return TEMPLATEPATH . '/';
    
        }
    
    }
    
    ?>
    

3 个答案:

答案 0 :(得分:4)

如果您将functions.php文件放入当前主题目录,请按以下步骤进入您的functions.php文件

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

如何删除BOM

为了删除BOM,Lafontaine建议使用免费的十六进制编辑器免费软件实用程序XVI32。编辑器无法安装,您可以直接从ZIP运行EXE文件。这个过程很简单 - 只需将“受影响的”PHP文件(在我的情况下为wp_config.php)拖到XVI32中,它就会以一个整齐的字节网格打开。然后,您应该看到文件中的前三个字节是“”,后跟php标记。

如果确实如此,则应依次选择每个字符并删除它(按Del键)。然后,当您保存(Ctrl + S)文件时,它将与以前完全相同,只是没有前导BOM。

完整文章链接: http://blog.scribz.net/2010/12/windows-live-writer-wordpress-unicode-bom-error/

答案 1 :(得分:2)

这是wordpress中非常常见的问题, 加上这个:

<?php ob_start(); ?>

在页面顶部。 快乐的编码!!

答案 2 :(得分:0)

这听起来类似于我在其他应用程序中遇到的问题。您是否在页面输出中的任何位置看到了字符?您可能遇到字节顺序标记问题。 http://en.wikipedia.org/wiki/Byte_order_mark这些取决于文件的编码。我不记得我是如何解决这个问题,但尝试以UTF-8保存文件?或者或许以某种方式告诉您的Web服务器文件是ANSI?