PHP 包含和文件路径出现问题


trouble with php include and file paths

我有一个与php include有关的问题。我有一个名为登录的文件夹和另一个文件夹文件。我在文件中有一个页脚.php它的样式表也与 style.css 位于同一文件夹中。所以,我想在登录中包含页脚.php.php作为<?php include('../files/footer.php');?>但它的 css 丢失了。如何解决这个问题?

您登录.php扩展一些布局.php其中包含所有必需的CSS文件。

当你编写你的html代码时,使用完整的url(以http://开头)到你的css和js文件中的<head>。这样您就不会遇到有关相对路径的问题

在头部,你应该为你的css链接使用绝对路径:

<link rel="stylesheet" href="http://localhost/your-main-folder/files/footer.css" />

或者你可以使用这个:

<base href="http://localhost/your-main-folder/" />
<link rel="stylesheet" href="files/footer.css" />