Wordpress无法修改标头信息 - header.php已发送的标头

时间:2016-10-10 13:57:37

标签: php wordpress header

我看到这是一个问了好几次的问题,但我真的尝试过一切都没有成功。具体来说,我得到了这个错误

  

警告:无法修改标头信息 - 已在/ Applications / MAMP / htdocs / kleeia中发送的标头(输出从/Applications/MAMP/htdocs/kleeia/wp-content/themes/Kleeia/header.php:14开始)第1174行/wp-includes/pluggable.php

当然去我的header.php:14我看不出任何可疑的东西,至少根据奇怪的错字或回声。这是我的header.php

<?php
/**
 * @package WordPress
 * @subpackage Kleeia
 * @since Kleeia
 */
?>
<!doctype html>
<html lang="en-us">
<head>
    <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');
            wp_head();
            global $current_user, $wpdb, $pagenow;
            wp_get_current_user();
            $uid = $current_user->ID;
            $user = get_userdata($current_user->ID);
            $userlogin = $user->user_login;
            //private messages
            if(is_user_logged_in()):
                $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 );
            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 '<style> #footer { background:#'.$KleeiaDev_color_for_footer.' }</style>'; 
            }
            $KleeiaDev_color_for_bk = get_option('KleeiaDev_color_for_bk');
            if(!empty($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');
            if(!empty($KleeiaDev_color_for_top_links))
            {
                echo '<style> .top-bar { background:#'.$KleeiaDev_color_for_top_links.' }</style>'; 
            }
            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(); ?>
</head>

在此之前,我已取消所有插件但未成功,请检查我的所有主题文件,以查看<?php ?>标记之前或之后是否有某些字符或空行。

更深入我只在我的 wp-login.php 中出现此错误,并在第一次尝试时导致非登录操作。基本上如果我插入凭据,我会被重定向到相同的登录页面,并且只有在刷新后才会进入管理仪表板。

作为一个自定义登录页面,我猜这可能是第一部分中的一些问题。

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 = '';
        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'] ) && ($_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']) );
        }
        /*PART MISSING BEFORE*/
        $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 );
        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 );

任何帮助都会非常感激,甚至可以链接一些已经讨论过此问题的文章或主题。

1 个答案:

答案 0 :(得分:1)

发送标头前没有输出!

必须在进行任何输出之前调用发送/修改HTTP标头的函数。否则呼叫失败:

以下内容可能会解决您的问题,因为这是在WordPress中。 我有这个问题(标题已经发送)很多时候,大部分选项2都适合我。

选项1:删除WordPress中 functions.php 文件末尾的空白行

选项2:在最顶行的 wp-config.php 中添加以下功能并检查。如果需要,那么只需更新永久链接一次。

ob_start();