【问题标题】:Why wont my PHP Include statements work?为什么我的 PHP Include 语句不起作用?
【发布时间】:2014-07-24 17:43:09
【问题描述】:

我正在尝试在我的网页上使用 php。 index.php 页面中的 php 有效,但 include 语句除外。 echo 语句正常工作。我尝试了各种使用包含语句的方法,您可以在此处看到。有3种不同的方法。我也尝试过不带括号使用它们。我在 Index.php 中引用的三个文件也都位于 index.php 所在的同一目录中。我没有尝试过,但我无法弄清楚。

索引.php:

<?php
echo 'test';
session_start();
echo 'test';
include($_SERVER['DOCUMENT_ROOT']."header.php");
include("connect.php");

$database = 'NJVCtestDB';
$server = '10.3.171.108';
echo getcwd();
?>
<p>Index.php</p>
<?php
echo 'test';
 require("footer.php");?>

header.php:

<!DOCTYPE html>
<head>
<?php

session_start()
echo 'test';

?>
<title></title>
</head>
<body>

页脚.php:

<p>footer.php</p>
</body>
</html>

【问题讨论】:

  • 你确定你的路径是正确的吗?
  • 从您的 index.php 文件中创建一个echo __DIR__; 并查看输出目录是否包含您引用的footer.phpconnect.php 文件。另外不要忘记$_SERVER['DOCUMENT_ROOT'] not 是否有斜杠。
  • 最好先阅读:stackoverflow.com/questions/8028957/…。另外,在您包含连接脚本之后设置您的数据库服务器数据有什么意义?你应该先设置这些东西。
  • 您确定文件名称正确吗? PHP 区分大小写。
  • 不知道这是否是问题,但 doctype 不是 html 标记 - 您缺少打开的 html 标记

标签: php


【解决方案1】:

我想你在路上少了一个渣,

include($_SERVER['DOCUMENT_ROOT']."header.php");

应该是:

include($_SERVER['DOCUMENT_ROOT']."/header.php");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-16
    • 2012-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 2011-12-20
    相关资源
    最近更新 更多