简体   繁体   中英

Cannot modify header information - headers already sent by php error after copying files

I am moving my wordpress website to another server.

I have just copied current files and uploaded them into new hosting through ftp.

And now when I'm trying to access then website I get the following errors:

Warning: Cannot modify header information - headers already sent by (output started at D:\inetpub\vhosts\domain.co.uk\httpdocs\wp-content\plugins\contact-form-with-captcha\cfwc-main.php:473) in D:\inetpub\vhosts\domain.co.uk\httpdocs\wp-content\plugins\woocommerce\classes\class-wc-session-handler.php on line 63

Warning: Cannot modify header information - headers already sent by (output started at D:\inetpub\vhosts\domain.co.uk\httpdocs\wp-content\plugins\contact-form-with-captcha\cfwc-main.php:473) in D:\inetpub\vhosts\domain.co.uk\httpdocs\wp-includes\pluggable.php on line 875

I did not modify any files, I just copied them as they were. Tried to remove any additional spaces at the end of both files but it didn't help.

Also I opened the file cfwc-main.php which says where the problem originated and removed trailing spaces after ?> and now I cannot access the website at all and getting

The page isn't redirecting properly

error. Putting back spaces or typing new ones fixes redirecting error.

But headers problem still appears.

What to do?

Just Check the file on which you have this error. You need to remove the extra spaces between php tag and also make sure their should not be an extra space at the end of the code.

Try By Remove Whitespace before <?php or after ?> 

THERE SHOULD BE NO BLANK SPACES HERE
<?php  

   echo "your code here";

?>
DO CHECK FOR BLANK SPACES HERE AS WELL; THIS LINE (blank line) SHOULD NOT EXIST.

You may also add

ob_start();

at the start of the file for the solution.

may be problem occurs due to extra space before php opening tag or after php closing tag.

<?php opening tag
?>  closing tag

so please open the listed file having error and paste the content into any another editor and check for the extra space and remove it

it works for me previsouly.

I have come across this problem on just a few occasions, and when I've tried all the obvious I go back to basics.

  1. Make a backup of your existing cfwc-main.php
  2. Create a brand new cfwc-main.php file using a plain-text editor (eg notepad).

Start off very simple:

<?php
  echo "Hello World";
?>
  1. Upload this, overwriting the existing cfwc-main.php and test. It will complain about the missing plugin functions, but you should not see the header or redirect warnings.
  2. Add code from the original a bit at a time, and test again.

eg

<?php
  // add the admin options page

  add_action('admin_menu', 'plugin_admin_add_page');

  function plugin_admin_add_page() {
    add_options_page(
      'Contact Form With Captcha Plugin Page', 
      'Contact Form With Captcha', 
      'manage_options', 
      'contact-form-with-captcha', 
      'plugin_options_page'
    );
  }

?>
  1. Assuming no errors/warnings are returned, build it up from there. I have put this down to non-visible control characters, so be careful when copying/pasting to note what you have done so you can reverse it should anything pop up.

The other approach is to use a text editor that will show you non-visible characters (eg Notepad++) and remove any you find from the code.

As per @Priya comment under one of the answers I disabled the plugin (just renamed plugin folder) and also another one which were causing the same problem and the error has gone.

Thank you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM