-2

Possible Duplicate:
“Warning: Cannot modify header information - headers already sent by” error

In building a login form to plug into the wordpress system, all of a sudden despite working earlier. Ignore these stars in the error they are just to avoid public display of the webste.

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

The codex says this is caused by space before and after the opening and closing , but there is not any. The offending line, ie. the one I can remove is $user = wp_signon( $creds, false ); to make it not cause this error, however then it doesn't do what I want it to.

The code

<?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();?>
Community
  • 1
  • 1
Walrus
  • 19,801
  • 35
  • 121
  • 199

2 Answers2

3

The headers have already been sent because some content has been sent (the space between your <?php ?> tags - yes, space is content too), content requires headers to be sent first, and you can't modify the headers after they have already been sent.

Combine the two into one to eliminate the space between them by changing

<?php get_header(); ?>

 <?php 

 $creds = array();
 ...

to

<?php 
    get_header();
    $creds = array();
    ...
Seth Carnegie
  • 73,875
  • 22
  • 181
  • 249
  • It is as Seth says. You can't send any browser headers, such as a Location to redirect, once you've sent any content. In this case, your space. – Cylindric Dec 05 '11 at 15:39
  • Tried that but it did not work either – Walrus Dec 05 '11 at 15:42
  • @RobinKnight does the function `get_header` `echo` or `print` or otherwise output anything? If it does, then you'll have to delay calling that until after you've modified the header info with `wb_redirect` – Seth Carnegie Dec 05 '11 at 15:44
  • 1
    @Seth, well done indeed. Yes it does. I tried moving it earlier to no avail so it must have been a combination – Walrus Dec 05 '11 at 15:48
2
<?php get_header(); ?>
    <----output started here
 <?php 

ANY whitespace/text that is outside of <?php ?> tagsets is treated as output by PHP.

Marc B
  • 356,200
  • 43
  • 426
  • 500