title: Wordpress Cannot modify header information - headers already sent by header.php
body: <p>I see that this is a question asked several times, but I've really tried everything around without success. Specifically I get this error</p>
  
  <blockquote>
    <p>Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/kleeia/wp-content/themes/Kleeia/header.php:14) in /Applications/MAMP/htdocs/kleeia/wp-includes/pluggable.php on line 1174</p>
  </blockquote>
  
  <p>Of course going to my <code>header.php:14</code> I can't see anything suspicious, at least according to weird typo or echos. Here is my <code>header.php</code>.</p>
  
  <pre><code>&lt;?php
  /**
   * @package WordPress
   * @subpackage Kleeia
   * @since Kleeia
   */
  ?&gt;
  &lt;!doctype html&gt;
  &lt;html lang="en-us"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8" /&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt; 
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt; 
      &lt;title&gt;&lt;?php wp_title(); ?&gt;&lt;/title&gt;
      &lt;link rel="shortcut icon" href="&lt;?php echo get_stylesheet_directory_uri(); ?&gt;/favicon.ico" /&gt;
      &lt;link rel="stylesheet" type="text/css" rel="stylesheet" href="&lt;?php echo get_template_directory_uri(); ?&gt;/style.css" /&gt;
      &lt;link rel="pingback" href="&lt;?php bloginfo( 'pingback_url' ); ?&gt;" /&gt;
      &lt;?php ini_set('display_errors','1'); ini_set('display_startup_errors','1'); error_reporting (E_ALL);include('index.php');
              wp_head();
              global $current_user, $wpdb, $pagenow;
              wp_get_current_user();
              $uid = $current_user-&gt;ID;
              $user = get_userdata($current_user-&gt;ID);
              $userlogin = $user-&gt;user_login;
              //private messages
              if(is_user_logged_in()):
                  $the_group_uid = isset($_COOKIE["v_group_id"]) &amp;&amp; !empty($_COOKIE["v_group_id"]) ? trim(strip_tags($_COOKIE["v_group_id"])) : "";       
                  $session_detail = vpb_get_the_user_detail($uid);
                  $session_username = strlen($session_detail[0]) &gt; 40 ? ucfirst(substr($session_detail[0],0,40)) : ucfirst($session_detail[0]);
                  $session_uid = $session_detail[1];
                  $session_email = $session_detail[2];
                  $session_photo = $session_detail[3];
                  $session_country = $session_detail[4];
                  $session_firstname = get_user_meta($uid,'first_name', true );
                  $session_lastname = get_user_meta($uid,'last_name', true );
              endif;
              //end messages
              $logo = get_option('KleeiaDev_logo_url');
              if(empty($logo))
              {
                  $logo = get_bloginfo('template_url').'/images/logo.png';
                  $logo = apply_filters('KleeiaDev_logo_url', $logo);
              }
              $logo_options = '';
              $logo_options = apply_filters('KleeiaDev_logo_options', $logo_options);
              //=============== Project Numbers
              $KleeiaDev_color_for_footer = get_option('KleeiaDev_color_for_footer');
              if(!empty($KleeiaDev_color_for_footer))
              {
                  echo '&lt;style&gt; #footer { background:#'.$KleeiaDev_color_for_footer.' }&lt;/style&gt;'; 
              }
              $KleeiaDev_color_for_bk = get_option('KleeiaDev_color_for_bk');
              if(!empty($KleeiaDev_color_for_bk))
              {
                  echo '&lt;style&gt; body { background:#'.$KleeiaDev_color_for_bk.' }&lt;/style&gt;';    
              }
              $KleeiaDev_color_for_top_links = get_option('KleeiaDev_color_for_top_links');
              if(!empty($KleeiaDev_color_for_top_links))
              {
                  echo '&lt;style&gt; .top-bar { background:#'.$KleeiaDev_color_for_top_links.' }&lt;/style&gt;'; 
              }
              if(isset($_POST['save-payments'])){
                  $personal_info = trim($_POST['paypal_email']);
                  update_user_meta($uid, 'paypal_email', $personal_info);
                  $personal_info = trim($_POST['payza_email']);
                  update_user_meta($uid, 'payza_email', $personal_info);
                  $personal_info = trim($_POST['moneybookers_email']);
                  update_user_meta($uid, 'moneybookers_email', $personal_info);
              }   
      do_action('KleeiaDev_before_head_tag_closes');
      flush(); ?&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>Before this, I've deactivated all plugins without success and check all my theme files to see if there are some characters or empty lines before or after <code>&lt;?php ?&gt;</code> tags.</p>
  
  <p>Going deeper I get this error only in my <strong>wp-login.php</strong> and it causes a non-login action at the first attempt. Basically If I insert the credentials, I get redirected to the same login page and only after refreshing I get to the admin dashboard.</p>
  
  <p>Being a custom login page I only guess that could be some problem in this first part.</p>
  
  <pre><code>global $wpdb, $error, $wp_query, $current_theme_locale_name;
          if (!is_array($wp_query-&gt;query_vars))
          $wp_query-&gt;query_vars = array();
          $action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : null);
          $error = '';
          nocache_headers();
          $loginpath = wp_login_url();
          //header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset'));
          if ( defined('RELOCATE') ) 
          { // Move flag is set
              if ( isset( $_SERVER['PATH_INFO'] ) &amp;&amp; ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
              $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
              $schema = ( isset($_SERVER['HTTPS']) &amp;&amp; strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
              if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_option('siteurl') )
              update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) );
          }
          /*PART MISSING BEFORE*/
          $secure = ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) &amp;&amp; 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
          setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
          if ( SITECOOKIEPATH != COOKIEPATH )
          setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
          $http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
          $interim_login = isset($_REQUEST['interim-login']);
          /***********************/
          do_action( 'login_init' );
          do_action( 'login_form_' . $action );
  </code></pre>
  
  <p>Any help would be really appreciated, even linking some article or topic already discussing this issue.</p>