PHP标头信息不可修改 - 无理由错误

时间:2011-12-05 15:35:59

标签: php wordpress

  

可能重复:
  “Warning: Cannot modify header information - headers already sent by” error

在构建登录表单以插入wordpress系统时,尽管工作较早,但突然间。在错误中忽略这些星星只是为了避免公开展示网页。

Warning: Cannot modify header information - headers already sent by (output started at /home/divethe1/public_html/**********.com/wp-content/themes/RIKsoft/header.php:2) in /home/divethe1/public_html/********.com/wp-includes/pluggable.php on line 738

Codex说这是由开场和收盘前后的空间引起的,但没有。违规行,即。我可以移除的是$user = wp_signon( $creds, false );,以使其不会导致此错误,但是它不能达到我想要的效果。

代码

<?php get_header(); ?>

 <?php 

 $creds = array();
$creds['user_login'] = $_POST['LOGuser'];
$creds['user_password'] = $_POST['LOGpass'];
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) )
   echo $user->get_error_message();

  ?>

        <?php if ( is_user_logged_in() ) { wp_redirect( $_POST['redirect'] ); exit; } 

        else { ?>

        <div class="panel log autoc">
    <div class="title"><b>LOG IN</b></div>
    <form action="http://www.robin-knight.com/access/" method="post">
        <label>Email Address<input name="LOGuser" type="text"></label>
        <label>Password<input name="LOGpass" type="password"></label>
        <input type="submit" class="button" value="Log In">
    </form>
</div>

        <?php }?>


<?php get_footer();?>

2 个答案:

答案 0 :(得分:3)

标题已经发送,因为已发送了一些内容(<?php ?>标记之间的空格 - 是的,空格也是内容),内容需要先发送标题,而您无法修改它们已被发送后的标题。

将两者合二为一,以通过更改

来消除它们之间的空间
<?php get_header(); ?>

 <?php 

 $creds = array();
 ...

<?php 
    get_header();
    $creds = array();
    ...

答案 1 :(得分:2)

<?php get_header(); ?>
    <----output started here
 <?php 

任何 <?php ?>标记集之外的空白/文本被PHP视为输出。