Wordpress Cannot modify header information - headers already sent by header.php


I see that this is a question asked several times, but I've really tried everything around without success. Specifically I get this error

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

Of course going to myheader.php:14 I can't see anything suspicious, at least according to weird typo or echos. Here is myheader.php.

 * @package WordPress
 * @subpackage Kleeia
 * @since Kleeia
<!doctype html>
<html lang="en-us">
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title><?php wp_title(); ?></title>
    <link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />
    <link rel="stylesheet" type="text/css" rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/style.css" />
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
    <?php ini_set('display_errors','1'); ini_set('display_startup_errors','1'); error_reporting (E_ALL);include('index.php');
            global $current_user, $wpdb, $pagenow;
            $uid = $current_user->ID;
            $user = get_userdata($current_user->ID);
            $userlogin = $user->user_login;
            //private messages
                $the_group_uid = isset($_COOKIE["v_group_id"]) && !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]) > 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 );
            //end messages
            $logo = get_option('KleeiaDev_logo_url');
                $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');
                echo '<style> #footer { background:#'.$KleeiaDev_color_for_footer.' }</style>'; 
            $KleeiaDev_color_for_bk = get_option('KleeiaDev_color_for_bk');
                echo '<style> body { background:#'.$KleeiaDev_color_for_bk.' }</style>';    
            $KleeiaDev_color_for_top_links = get_option('KleeiaDev_color_for_top_links');
                echo '<style> .top-bar { background:#'.$KleeiaDev_color_for_top_links.' }</style>'; 
                $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);
    flush(); ?>

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<?php ?> tags.

Going deeper I get this error only in my wp-login.php 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.

Being a custom login page I only guess that could be some problem in this first part.

global $wpdb, $error, $wp_query, $current_theme_locale_name;
        if (!is_array($wp_query->query_vars))
        $wp_query->query_vars = array();
        $action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : null);
        $error = '';
        $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'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
            $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
            $schema = ( isset($_SERVER['HTTPS']) && 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']) );
        $secure = ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) && 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
        setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
        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 );

Any help would be really appreciated, even linking some article or topic already discussing this issue.




No output before sending headers!

Functions that send/modify HTTP headers must be invoked before any output is made. Otherwise the call fails:

Following may resolve your issue considering this is in WordPress. I had this issue (header already sent) many time and mostly option 2 worked for me.

Option 1 : Remove any blank line at the end of functions.php file in WordPress

Option 2 : Add following function in wp-config.php at top most line and check. If needed after that than update permalink once.


People are also looking for solutions to the problem: php - Unable to upload files over 500MB while upload_max_filesize is set to 1G


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.