我试图添加一个if条件的开始和if条件的结尾包含在另一个文件中的单独文件中。解析错误:语法错误,单独文件上的文件意外结束
我有一个名为cp.php文件,该文件包含的header.php和footer.php,看起来像这样:
<?php
require_once "includes/header.php";
?>
<p>Welcome <?php echo htmlentities($_SESSION['username']); ?>!</p>
<p>
This is an example protected page. To access this page, users
must be logged in. At some stage, we'll also check the role of
the user, so pages will be able to determine the type of user
authorised to access the page.
</p>
<?php
require_once "includes/sidebar.php";
require_once "includes/footer.php";
?>
的header.php
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
sec_session_start();
?>
<html>
<head></head>
</body>
<?php if (login_check($db) == true) : ?> // this if I am trying to end in footer.php
footer.php
<?php else : ?>
<?php header('index.php');
<?php endif; ?>
</body>
</html>
但我得到Parse error: syntax error, unexpected end of file in header.php on line 9
这将是与<?php if (login_check($db) == true) : ?>
线。我在哪里弄错了。
试过这个,它只在我登录时才起作用。如果我注销它不会去其他地方,将我重定向到index.php。 – user3467855
有没有其他的需要。这段代码意味着如果我没有登录然后将我重定向到index.php,反正什么也不做,继续运行这个脚本。 (假设login_check在登录时返回true,如果没有则返回true) –
在这种情况下,它的工作原理是这样的:即使我退出了,我仍然可以查看受保护的内容,而不是将其重定向到'index.php' – user3467855