【问题标题】:Cannot modify header information error in Wordpress [duplicate]无法修改 Wordpress 中的标题信息错误 [重复]
【发布时间】:2012-09-23 10:48:41
【问题描述】:

我在尝试登录管理面板时遇到此错误。我无法理解它。

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. 通过重命名禁用插件目录

...错误仍然存​​在

我唯一可以尝试的是有人在 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,而且我不完全了解此代码的功能,也没有详细说明将其准确放置在何处。有更好的建议吗?


Themes 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 . '/';

    }

}

?>

【问题讨论】:

  • 删除&lt;?之前的前导空格,它应该可以工作。
  • 正如我提到的,notepad++ 或 HTML 工具包工具编辑器没有前导空格,并保存在 ANSI 中。为了进一步运行它,我什至再次下载了文件并只填写了必要的部分。

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


【解决方案1】:

如果你的当前主题目录中有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/

【讨论】:

  • 我无法让它工作。我没有编程经验。我应该把它放在哪里?
  • 将我的答案代码添加到 function get_root_directory( $path ) 这一行上方的 function.php 文件中
  • 我用 UTF-8 的 c-panels 代码编辑器编辑了主题文件。没运气。我对这个问题感到非常沮丧。我什至尝试通过临时重命名主题和插件以及将基本的 wordpress 主题 211 添加到新的主题目录来禁用主题和插件,但错误仍然存​​在。我不知道从这里去哪里。
  • 你能把你编辑的function.php文件粘贴到codepad.org吗?
  • 把头撞到墙上后,我决定在 ansi (1983) 中打开配置文件,它看起来像这样:ʼn»¿
【解决方案2】:

这是 wordpress 中很常见的问题, 添加这个:

<?php ob_start(); ?>

在页面顶部。 编码愉快!

【讨论】:

  • 无需编辑 wp_config 文件。只需将其放在页面顶部,您可以在其中编写 header("location: your_url");
  • 在wordpress核心文件中编辑根本不是什么好事。
  • 我为我的无知道歉,但我没有编程经验。你说的是哪个页面?也就是说,我在 ansi (1983) 中打开了配置文件,它看起来像这样:ʼn»¿
  • 在您的 wordpres 主题文件夹中,您可以看到许多文件。这是您在页面中包含的文件(模板文件)。只需将此行放在文件的最顶部即可。另一个,如果你没有得到任何东西,试着找到 header.php 并将这行代码放在那里。希望它有意义。
  • 找到 header.php 文件。在 上方的第一行插入代码。没有成功。你不认为打开配置文件ansi时显示的字符是这个错误的真正原因并且可以迅速修复吗?
【解决方案3】:

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

【讨论】:

  • 您好 Jacob,感谢您的回复。我无法检测到任何 BOM/空格。我以前使用 Filezilla 传输时使用过 HTML texk 套件和记事本++,但现在我在 UTF-8 中使用 c-panel 代码编辑器。
  • 好的。当我在 ANSI (1983) 中打开文件时,我找到了 BOM。但是问题仍然存在,因为我唯一可见的是 BOM 和几条起始行:ʼn»¿&lt;?php /** * WordPressin perusasetukset. * * T BOM 在 UTF-8 中不可见,我无法在 ANSI 中编辑文件。如何摆脱这种烦恼?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 2020-07-28
  • 2011-11-14
相关资源
最近更新 更多