包含对索引文件不起作用

时间:2014-01-09 18:17:43

标签: php html include

我有一些包含文件的问题。我有两个页面,我使用完全相同的起始行10行。

    <html>
    <head>
    <?php include "../~13097377/include/head.html"; ?>
    </head>
    <body id="body" >
    <div style="background-color: #E0ECF8; min-height: 100%;">
    <div style="position:fixed; background-color: #E0ECF8;">
    <?php include "../~13097377/include/slideshow.html"; ?>
    <?php include "../~13097377/include/menu.html"; ?>
    <div style="padding: 0px 20px 0px 20px;">

http://eduweb.hhs.nl/~13097377/index.php
http://eduweb.hhs.nl/~13097377/contact/contact.php

联系页面反应正常,但索引页面出现了很多错误,例如“无法打开流:/ var / www中没有此类文件或目录”

有人知道如何解决这个问题吗?

3 个答案:

答案 0 :(得分:1)

您在include中使用了相对路径../etc...,这意味着正在检查的路径与您正在运行include指令的脚本的位置相对。

这意味着,假设您的文档根目录为/var/www/site/html

/var/www/site/html/index.php           -> /var/www/site/~13097377/include/head.html
/var/www/site/html/contact/contact.php -> /var/www/site/html/~13097377/include/head.html

除非您的doc_root和doc_root / contact目录中都有~13097377目录,否则这就是您收到错误的原因。你告诉PHP在一个不存在的地方寻找你的文件。

答案 1 :(得分:1)

当您的文件位于不同级别的目录中时,相对路径不起作用。您可以使用相对于Web服务器根目录的绝对路径:

<?php include $_SERVER['DOCUMENT_ROOT'] . "/~13097377/include/slideshow.html"; ?>
<?php include $_SERVER['DOCUMENT_ROOT'] . "/~13097377/include/menu.html"; ?>

答案 2 :(得分:0)

?php include的所有实例更改为<?php include

所有PHP代码都应在<?php开放标记和?>结束标记之间。

修复语法错误后,请检查包含路径。它们可能是相对的,但可能不依赖于Web服务器和PHP配置。

相关问题