Title: Cannot modify header information
Last modified: August 18, 2020

---

# Cannot modify header information

 *  Resolved [Nathan](https://wordpress.org/support/users/nhadsall/)
 * (@nhadsall)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-modify-header-information-165/)
 * We are constantly getting `Cannot modify header information - headers already
   sent by (output started at /home/USER/public_html/wp-content/plugins/affiliates-
   manager/imp.php:21)`
 * It looks like like 18 that tries to send `header("Content-Length: $length");`
   after sending the content?

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [affmngr](https://wordpress.org/support/users/affmngr/)
 * (@affmngr)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-modify-header-information-165/#post-13278628)
 * [@nhadsall](https://wordpress.org/support/users/nhadsall/), Can you please disable
   impressions in the settings (Affiliates > Settings > General)?
 *  Thread Starter [Nathan](https://wordpress.org/support/users/nhadsall/)
 * (@nhadsall)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-modify-header-information-165/#post-13294044)
 * I’ve done that now. I assume that will fix it since that code won’t be run. But
   can we fix the code 🙂 It’s not a huge issue, but it’s clogging up the error 
   log.
 * Thanks for the help!
 *  Plugin Author [affmngr](https://wordpress.org/support/users/affmngr/)
 * (@affmngr)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-modify-header-information-165/#post-13299136)
 * [@nhadsall](https://wordpress.org/support/users/nhadsall/), We have made some
   changes to the file that may fix this error on your site. Please contact us if
   you are interested in testing it: [https://wpaffiliatemanager.com/contact/](https://wpaffiliatemanager.com/contact/)
 *  Thread Starter [Nathan](https://wordpress.org/support/users/nhadsall/)
 * (@nhadsall)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-modify-header-information-165/#post-13311363)
 * We deactivated that feature, but are still getting the error. I’ll send my contact
   info to you. Thanks!
 *  Plugin Author [affmngr](https://wordpress.org/support/users/affmngr/)
 * (@affmngr)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-modify-header-information-165/#post-13326156)
 * [@nhadsall](https://wordpress.org/support/users/nhadsall/), We have emailed you
   with an updated copy of the plugin. Please let us know if it fixes the issue.
 *  Thread Starter [Nathan](https://wordpress.org/support/users/nhadsall/)
 * (@nhadsall)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-modify-header-information-165/#post-13329418)
 * Sadly, it’s still there 🙁
 *     ```
       header('Content-type: image/gif');
       header('Connection: close');
   
       // Output a 1x1 pixel transparent gif
       ob_start();
       echo base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7');
       $length = ob_get_length();
   
       header("Content-Length: $length");
       ```
   
 * It says the error is on line 21, so the `ob_end_flush()`. It looks like data 
   has already been sent out by time you are adding headers on line 10 and 11. Even
   it that is not true, line 18 is sending headers after an echo, which would also
   throw an error.
 *  Thread Starter [Nathan](https://wordpress.org/support/users/nhadsall/)
 * (@nhadsall)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-modify-header-information-165/#post-13329502)
 * Ah ha! I found it. The issue was different. I looked at the log file and realized
   it wasn’t the header! It was the gif output.
 * `[28-Aug-2020 16:43:16 UTC] PHP Warning: Cannot modify header information - headers
   already sent by (output started at /home/USER/public_html/wp-content/plugins/
   affiliates-manager/imp.php:15) in /home/USER/public_html/wp-content/plugins/affiliates-
   manager/classes/ClickTracking.php on line 40`
 * line 40 is trying to set a cookie in the header!
 *     ```
       if(!empty($aff_id)){
           $cookie_life_time = wpam_get_cookie_life_time();
           setcookie('wpam_id', $aff_id, $cookie_life_time, "/", COOKIE_DOMAIN);
       }
       ```
   
    -  This reply was modified 5 years, 9 months ago by [Nathan](https://wordpress.org/support/users/nhadsall/).
 *  Thread Starter [Nathan](https://wordpress.org/support/users/nhadsall/)
 * (@nhadsall)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-modify-header-information-165/#post-13329565)
 * Okay, once I realized that was the problem, I just moved the gif echo to the 
   end:
 *     ```
       <?php
   
       /* Connection: close and Content-Length headers are sent, so that browsers disconnect
        * early on to minimize connection time */
   
       //The following outputs a 1x1 pixel gif. It is not really need for the functionality but nice to have.
       ignore_user_abort(true);
       // ob_end_clean();
       $gif = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7');
       $length = strlen( $gif );
   
       header('Content-type: image/gif');
       header('Connection: close');
       header("Content-Length: $length");
       //End of gif output.
   
       require_once ("../../../wp-load.php");
       require_once ("config.php");
       require_once ("source/Tracking/RequestTracker.php");
   
       if (isset($_GET[WPAM_PluginConfig::$RefKey])
               && get_option(WPAM_PluginConfig::$AffEnableImpressions)) {
           try {
               $requestTracker = new WPAM_Tracking_RequestTracker();
               $request_data = array_map('strip_tags', $_GET);
               $requestTracker->handleImpression($request_data);
           } catch (Exception $e) {
               wp_die("WPAM FAILED: " . $e->getMessage());
           }
       }
   
       echo $gif;
   
       exit;
       ```
   
 *  Thread Starter [Nathan](https://wordpress.org/support/users/nhadsall/)
 * (@nhadsall)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-modify-header-information-165/#post-13356134)
 * Just following up to see if you will be able to apply this fix or something similar
   so it doesn’t break again on the next update. Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Cannot modify header information’ is closed to new replies.

 * ![](https://ps.w.org/affiliates-manager/assets/icon-128x128.png?rev=981249)
 * [Affiliates Manager](https://wordpress.org/plugins/affiliates-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/affiliates-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/affiliates-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/affiliates-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/affiliates-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/affiliates-manager/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [Nathan](https://wordpress.org/support/users/nhadsall/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/cannot-modify-header-information-165/#post-13356134)
 * Status: resolved