Warning: Cannot modify header information – headers already sent by (output started at /home/onoboss/onoboss_wiki/wp-content/plugins/wp-limit-posts-automaticallybon/wp-limit-posts-automatically.php:1) in /home/onoboss/onoboss_wiki/wp-login.php on line 302

安装一个wordpress插件,登录wp-admin,报header already sent,

怎么判断是utf-8导致的呢?

output started at /home/onoboss/onoboss_wiki/wp-content/plugins/wp-limit-posts-automaticallybon/wp-limit-posts-automatically.php:1

这个提示你,输出开始的文件位置,注意最后一个1,即第一行!

可能的原因:

  1. utf-8 BOM(Byte Order Mark,字节序标记)
    在UTF8文件头加入:EF BB BF,表示自己是一个utf-8文件;浏览器会把EF BB BF当成字符输出。
  2. php脚本头 <?php,尾 ?>有任意字符,比如换行,空格
    [php]
    \n
    <?php

    ?>
    \n
    [/php]

解决方案:

  1. vim 去除utf-8 bom
    [shell]set nobomb;[/shell]
  2. php脚本,不使用结束符 ?>
    [php] <?php
    $a = 1;
    ?> // 可以不加这个结束符
    [/php]
  3. 开启输出缓冲
    [php]ob_start();[/php]