是的,我的建议是使用括号。现在你的代码基本上是这样的:
<?php
if($_SESSION['id']) {
echo '<div id="center" class="column">';
}
include("center.php");
echo'</div>
<div id="left" class="column">';
include("leftbar.php");
echo'</div>
<div id="right" class="column">';
include("rightbar.php");
echo '</div>';
} else {} <--- error is here because there is no open if statement since you didn't use brackets
echo '<h1>Staff please, <a href="index.php">login</a>
before accessing this page, no access to students.</h1>';
?>
请注意,由于您没有使用括号,因此您的 if 条件仅适用于以下代码行。当解析器命中 else 行时,没有打开的 if 条件与 else 相关。
您的代码应如下所示:
<?php
if($_SESSION['id']) {
echo '<div id="center" class="column">';
include("center.php");
echo'</div><div id="left" class="column">';
include("leftbar.php");
echo'</div><div id="right" class="column">';
include("rightbar.php");
echo '</div>';
} else {
echo '<h1>Staff please, <a href="index.php">login</a> before accessing this page, no access to students.</h1>';
}
?>