Unusual 'Headers already sent' error. No whitespace nor changing of the header

杀马特。学长 韩版系。学妹 提交于 2020-01-15 05:08:05

问题


Before you start telling me there are already 10000000 posts on this error, I know.

I am working on a wordpress plugin and am recieving the following error when submitting my edit pages:

Warning: Cannot modify header information - headers already sent by (output started at ***\wp-content\plugins\***\meta-class-load.php:1067) in ***\wp-includes\pluggable.php on line 934

What's different about this error is the line it references does not interface with the header, nor output content before. I have checked for whitespace surrounding php tags, and there is none :P

This is the contents (and surrounds) of line 1067:

        $name = $field['id'];
        $type = $field['type'];
        $old  = $this->get_meta($post->ID, $field); // THIS IS THE LINE
        $new = isset($_POST[$name]) ? $_POST[$name] : ($field['multiple'] ? array() : '');

Any ideas or solutions would be helpful. Thanks!


回答1:


Never output anything before sending the HEADER, if you do so you will not be able to send the header and it will throw an error !
It's also a good practice to set error_reporting(0) on production server to make sure that no error gets shown before header




回答2:


1067 is the line that outputs content. Line 934 is the one setting the header. I think you have them backwards.




回答3:


No output can be sent before all headers are sent. One of the files listed in the error, or possibly a file included by one of those files, is outputting something. It could be something intentional, a stray bit of white space, a warning or an error message.

To prevent the error you can try calling either ob_clean(); or ob_end_clean(); to clear the output buffer right before your header call. ob_end_clean(); is almost always successful in these cases.



来源:https://stackoverflow.com/questions/6714991/unusual-headers-already-sent-error-no-whitespace-nor-changing-of-the-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!