This is my code. This is the page where the form action directs to. The form is basically a sign up form. I am trying to create a new user and automatically signing him as well. The user is created but the signon doesn’t work. It says that the headers have already been specified.
This question might seems like the others on the forum but it is a bit different as I have taken care of using the sign on before calling headers.

<?php  
 /* 
 Template Name: Trial
 */ 
?> 
<?php 
if($_POST)
{  
                //ob_start(); 
                //echo "<h1> WTF </h1>";
                $email = $_REQUEST['user_email']; 
                session_start();
                $_SESSION['check']= 1;     
                $_SESSION['email']= $email;
                $_SESSION['firstname']=$_REQUEST['first_name'];
                $_SESSION['lastname']=$_REQUEST['last_name'];
                if (!email_exists($email)) 
                { 
                //$firstname = $_REQUEST['first_name'];
                $username = $_REQUEST['user_login'];
                $password = $_REQUEST['user_password'];
                $first_name= $_REQUEST['first_name'];
                if ( username_exists( $username ) )
                    {   
                        echo "<h1>Username In Use! Please enter another.</h1>";
                        sleep(5);
                        echo "<script>window.history.back();</script>";
                        //die();
                    }
                 echo 'That E-mail doesn't belong to any registered users on   this site,So registering....<br>'; 
                // Creating WP User
                wp_create_user( $username, $password, $email); 
                echo 'This email id is now registered thanks--->'.$email; 
                //ob_end_flush();
    //We shall SQL escape all inputs  
    $username = $wpdb->escape($_REQUEST['user_login']);  
    $password = $wpdb->escape($_REQUEST['user_password']);  
    //$remember = $wpdb->escape($_REQUEST['rememberme']);  
      $remember = "true";
        if($remember) 
            $remember = "true";  
        else 
            $remember = "false"; 
    $login_data = array();  
    $login_data['user_login'] = $username;  
    $login_data['user_password'] = $password;  
    $login_data['remember'] = $remember;  
    $user_verify = wp_signon( $login_data, true );   
    if ( is_wp_error($user_verify) )   
    {  
       echo "<span class='error'>Invalid username or password. Please try again!</span>";  
       exit();  
    } 
    else   
    {    
        echo "Problem here";
        die();
       echo "<script type='text/javascript'>url') ."'</script>";  
       exit();  
    }  
} 
else 
{   
        get_header();
        get_footer();  
}  
}
?>  

Read more here: wp_signon() giving problems : saying header already specified even though the header is called after using it


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: