when redirecting to php file the echo response is displayed 1st wich create header error

when redirecting to php file the echo response is displayed 1st wich create header error

hello evryone,
i have a small issue that i dont seem to get my head arround.
 
logincheck.php
<?php
.......
 
$return = true;
...
echo json_encode($return); 
?>
 
welcome.php
<?php
 
secured members content...
 
?>
 
index.php
 
<SCRIPT type="text/javascript" src="jquery-1.4.2.min.js"></SCRIPT>
<SCRIPT type="text/javascript" src="checklogin.js"></SCRIPT>
<?php
 
loginform
 
 
?>
 
 
 
checklogin.js
 
$(document).ready(function(){
 
 $('#submit').click(function() {
  
  $.ajax({
   type : 'POST',
   url : 'logincheck.php',
   dataType : 'json',
   asynchronous: false,







   data: {
    user :$('#username').val(),
    pass :$('#password').val(),
    
   },
 success : function(data){
   
     if(data.error==true)     {
   
     $("#msgbox").fadeTo(200,0.1,function()
   {
    
     $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
              function()
     {
   
    //redirect to secure page
    document.location.href='welcome.php';
















     return false;
 
     });
    
   });
    }
    else
    {
   
     $("#msgbox").fadeTo(200,0.1,function()
   {
   
     $(this).html('Wrong login detail ...').addClass('messageboxerror').fadeTo(900,1);
   });  
          }
  
 
  
   },
 error : function(XMLHttpRequest, textStatus, errorThrown) {
   
  $("#msgbox").fadeTo(200,0.1,function()
   {
     $(this).html('Error...').addClass('messageboxerror').fadeTo(900,1);
   }); 
   }
  });
  
  return false;
 });
});





























 
 
 
 
 
 
here is my problem the login mechanism is working ok, but when the user is redirected to the welcome.php the output of logincheck. php  echo json_encode($return);  for example true or 1 is displayed 1st so whatever come from welcome.php give error php Warning: Cannot modify header information - headers already sent by .......
 
can anyone help plz
thanx.