Web Hosting Talk







View Full Version : PHP Question (Include not working)


Nibbles McTwitch
12-27-2005, 03:29 PM
Ok heres the deal i am trying to include a header but it's not working.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
include($_SERVER['DOCUMENT_ROOT'].'/header.html');
?>
</body>
</html>

So what am i ding wrong?

Josh.Streit
12-27-2005, 03:56 PM
I got this one guys, well, I hope...

Hi Nibbles, I think I know what your doing, but I am not 100% positive: Are you tring to go to the root of your site and get header.html?

$_SERVER['DOCUMENT_ROOT'] tells the server to go to the main source of the document, if I am not mistaken. I am not sure how your website is setup (with folders and everything), but you could try this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
include('../header.html');
?>
</body>
</html>

That will include the lower level directories file ; header.html


You can try this also, though I did not test it I just wrote this on the fly

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

$dir = "directory_to_files/" //make this a directory to your files, include the forward slash at the end

include($dir . header.html);
?>
</body>
</html>

That will use the defined variable "dir" and set it in place for your include...


Now this is where I get confused, single quotes and double quotes, but I'll do the best i can.

Try using doubles quotes, as a THINK it runs the PHP through the string and outputs it, correct me if im wrong!


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
include("$_SERVER['DOCUMENT_ROOT']./header.html");
?>
</body>
</html>


Try all of those, and if it doesn't work still, just repost with your error (that would be helpful).

Hope this works!
Regards
Josh

Nibbles McTwitch
12-27-2005, 03:58 PM
I got this to work

<?php
include 'header.php';
?>

Thanks for the help.

Josh.Streit
12-27-2005, 04:09 PM
Lol... I thought you we're tring to do something far more advanced, lol...

Happy to see you got it working though.