if ((isset($username)) && (isset($userid))){
}else{
header( 'Location: teacherlogout.php' ) ;
}
我上面有一个 if/else 语句,我想做的是,如果满足 else 语句,则导航到该teacherlogout.php
页面。但不是这个,我收到一条错误消息:
Warning: Cannot modify header information - headers already sent by (output started at /:431) in / on line 1654
我不太明白我做错了什么?第 431 行只是var qremain = <?php echo (int)$_SESSION['textQuestion']; ?>;
一行代码。第 1654 行是该header( 'Location: teacherlogout.php' ) ;
行。这里发生了什么?
更新:
实际上使用ajax在后台导航到teacherlogout.php脚本会更好,如下所示:
<?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
}
?>