When I run wp_signon () I have several warning similar to this: "Warning: Cannot modify header information - headers already sent by (output started at /web/htdocs/www.example.com/home/wp-includes/class.wp-styles.php:237) in /web/htdocs/www.mysite.com/home/wp-includes/pluggable.php on line 892" It do the login anyway, and if I change page then does not give me no problem, but I can not understand these errors. I am attaching the login code. Thanks a lot in advance for the help!
header.php :
<div id="loginbar">
<?php $current_user = wp_get_current_user();
if(isset($_POST["submit"])){
custom_login();
}?>
<?php if(!is_user_logged_in()): ?>
<form name="frontlog" method="post">
<input id= "log" type="text" name="log" placeholder="Username">
<input id= "pwd" type="password" name="pwd" placeholder="Password">
<input type= "submit" name="submit" class="linkbuttonleft" id="loginbutton">
</form>
<a class="linkbuttonright" title="Registrati" href="http://www.example.com/registrazione/">
<img id="chiave" src="http://www.example.com/wp-content/themes/BiscuitsTheme/immagini/chiave.png" onmousedown="return false"></a>
<?php else: ?>
<p> <?php echo 'Benvenuto ' . $current_user->user_login;?> </p>
<a class="linkbuttonleft" title="Logout" href="<?php echo wp_logout_url( home_url() ); ?>"></a>
<img id="lucchetto" src="http://www.example.com/wp-content/themes/BiscuitsTheme/immagini/lucchetto.png" onmousedown="return false"></a>
<a class="linkbuttonright" title="Profilo" href="http://www.example.com/profilo/">
<img id="profilo" src="http://www.example.com/wp-content/themes/BiscuitsTheme/immagini/profilo.png" onmousedown="return false"></a>
<?php endif; ?>
</div>
functions.php :
function custom_login() {
$creds = array();
$creds = array(
'user_login' => $_POST["log"],
'user_password' => $_POST["pwd"],
'remember' => true
);
$user = wp_signon( $creds, false );
if ( is_wp_error($user) ) {
echo $user->get_error_message();
}
else {
wp_set_current_user( $user->ID, $user->name );
wp_set_auth_cookie( $user->ID, true, false );
}
};add_action( 'after_setup_theme', 'custom_login' );