在 html 和 php 中创建一个模板


Create a template in html and php

如何仅更改页面的内容而不更改周围的模板?

假设我有一个用户登录并看到他的帐户信息页面。如果页面只需要更改其中的某些元素怎么办?

这基本上是我所做的:

<?php
session_start();
if($_SESSION['user'] == 'stuff'){
?>
User account page with certain changes in its content (html)
<?php
} else {
?>
User account page that says "you need to login first" with the same template (html)
<?php
}
?>

因此,此处没有重定向。我该如何简化此操作,或者除了这种方式之外没有其他方法?

您也可以单独加载页眉和页脚。

主要内容将根据用户是否登录而变化。

首先对模板进行编码。然后将代码复制到PHP变量中 - 最好将其存储在一些"模板.php"文件中,然后调用它。接下来,只需执行print $header;即可设置。