0

I'm trying to use php on my webpages. The php in the index.php page works, except for the include statements. The echo statements work correctly. I've tried various methods of using the include statements which you can see here. There are 3 different kind of methods. I've also tried using them without parenthesis. The three files i'm referring to in Index.php are all in the same directory that index.php is placed in as well. Nothing works that i've tried and i cannot figure it out.

Index.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>

footer.php:

<p>footer.php</p>
</body>
</html>
Ryan Brady
  • 147
  • 1
  • 12
  • Are you sure your paths are correct? – John Conde Jul 24 '14 at 17:43
  • Do an `echo __DIR__;` from your index.php file and see if the outputted directory contains the `footer.php` and `connect.php` files you refer to. Also don't forget `$_SERVER['DOCUMENT_ROOT']` does **not** have a trailing slash. – sjagr Jul 24 '14 at 17:46
  • Better read this first: http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php. Plus what is the point of setting your DB server data **AFTER** you've included the connect script? You should be setting that stuff FIRST. – Marc B Jul 24 '14 at 17:46
  • Are you sure the file named correctly? PHP is case sensative. – durbnpoisn Jul 24 '14 at 17:47
  • Don't know if that's the problem but doctype is not an html tag - you are missing an openning html tag – Ofir Jul 24 '14 at 17:47

1 Answers1

0

You are missing a slag in your path I think,

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

Should be:

include($_SERVER['DOCUMENT_ROOT']."/header.php");
Takoyaro
  • 928
  • 7
  • 14