【问题标题】:"Warning: Cannot modify header information" error in wordpress [duplicate]wordpress中的“警告:无法修改标题信息”错误[重复]
【发布时间】:2012-07-03 22:54:34
【问题描述】:

我在开发插件时遇到此错误。
在 localhost 中工作正常,但在远程服务器中失败:

警告:无法修改标头信息 - 标头已由 (输出开始于 /path_wordpress/public_html/wp-admin/includes/template.php:1657)在 /path_wordpress/public_html/wp-includes/pluggable.php 在第 866 行

我已删除文件开头和结尾前后的所有空格(此错误的常见原因)并且不涉及任何会话。

还有什么原因?

===
编辑 1

wp-admin/includes/template.php:

$attributes = '';
if ( is_array( $other_attributes ) ) {
    foreach ( $other_attributes as $attribute => $value ) { // line 1657 
        $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
    }
} else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
    $attributes = $other_attributes;
}

===
编辑 2

wp-admin/wp-includes/pluggable.php:

if ( !function_exists('wp_redirect') ) :
/**
 * Redirects to another page.
 *
 * @since 1.5.1
 * @uses apply_filters() Calls 'wp_redirect' hook on $location and $status.
 *
 * @param string $location The path to redirect to
 * @param int $status Status code to use
 * @return bool False if $location is not set
 */ // line 866
function wp_redirect($location, $status = 302) {
    global $is_IIS;

【问题讨论】:

  • 有代码吗?另外,你知道冒犯的header是什么吗?
  • 另一个原因:您不止一次发送输出。无论如何,我们需要代码来审查
  • 在此错误之前您是否看到模板的任何部分,如果是,则模板已被回显。
  • 插件有好几个文件,这里就不放代码了。我不知道是什么文件导致了这个错误......
  • @sheikh-heera 不,没有模板输出。此错误发生在管理面板中。

标签: php wordpress session http-headers


【解决方案1】:

无法修改标头信息通常发生在您在某些 html 输出后尝试使用 header() 或重定向功能时。它不太可能位于 Wordpress 本机代码文件之一中,因此请检查您可能编写的一些尝试重定向页面的自定义代码。

参考:http://php.net/manual/en/function.header.php

【讨论】:

  • 谢谢,在此问题上停留了一段时间,但您发现“请记住,必须在发送任何实际输出之前调用 header(),无论是通过普通 HTML 标记还是文件中的空行, 或来自 PHP"
猜你喜欢
  • 1970-01-01
  • 2020-07-28
  • 1970-01-01
  • 1970-01-01
  • 2018-06-24
  • 2010-12-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多