Possible Duplicate:
PHP error: Cannot modify header information – headers already sent
Headers already sent by PHP
if ((isset($username)) && (isset($userid))){ 
}else{ 
header( 'Location: teacherlogout.php' ) ;
}
I have an if/else statement above, what I want to do is that if the else statement is met, then navogate to the teacherlogout.php page. But instead of this I am getting an error stating: 
Warning: Cannot modify header information - headers already sent by (output started at /:431) in / on line 1654 
I don't quite get what I am doing wrong? Line 431 is just a var qremain = <?php echo (int)$_SESSION['textQuestion']; ?>; line of code. Line 1654 is the header( 'Location: teacherlogout.php' ) ; line. What is happeing here?
UPDATE:
Actually will it be better to use ajax to navigate to teacherlogout.php script in background as so:
<?php   
}else{ 
echo "Please Login to Access this Page | <a href='./teacherlogin.php'>Login</a>";
?>
<script type="text/javascript">
        $.ajax({    
        url: "teacherlogout.php",
        async: false,
        type: "POST",
      });
</script>
<?php
}
?>
 
     
     
     
     
    