【问题标题】:php/html: Require doesn't work in basic html / php codephp/html: Require 在基本的 html / php 代码中不起作用
【发布时间】:2019-09-18 22:19:53
【问题描述】:

所以我试图将 header.php 导入到我的 index.php 文件中,但它不起作用。

header.php:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <header>
      <p> this should be on top</p>
    </header>

index.php:

<?php require "header.php"; ?>

<main>
  <p> this is the index</p>
</main>

<?php require "footer.php"; ?>

页脚.php:

<p> This should be on the bottom </p>
</body>

</html>

如果我打开 index.php,它只会显示 index.php 中写的内容。 我将所有文件保存在我的桌面文件夹中的一个文件夹中。

我只需将其拖入浏览器 (firefox) 即可打开 index.php。

【问题讨论】:

  • require 给出了致命错误。你的html文件一定有问题
  • "我打开 index.php" 你怎么打开呢?
  • 在我的 MAMP 服务器上运行良好。请检查以上是否保存为 .php 文件?
  • 你是直接打开你的index.php文件吗?

标签: php html require


【解决方案1】:

您需要使用网络服务器运行您的 PHP 脚本。

PHP 脚本在被浏览器打开之前需要由服务器解释。

要在本地运行您的项目,有多个应用程序,如 Xampp(适用于 Windows)或 Mampp(适用于 Mac)、Docker 或事件直接在您的机器中安装 Web 服务器,安装 Nginx 或 Apache。

【讨论】:

  • 非常感谢,那是错误。我只是假设如果我在浏览器中打开它会起作用:)
猜你喜欢
  • 2019-09-16
  • 2017-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-31
  • 1970-01-01
  • 1970-01-01
  • 2011-01-13
相关资源
最近更新 更多