Forum Moderators: coopster

Message Too Old, No Replies

PHP Include Headers And Footers

PHP Include () Isn't Working!

         

ViciousJ

5:44 am on Jul 10, 2009 (gmt 0)

10+ Year Member



Alright, so I'm trying to get my site up and running...and I am using the <? include('/example/example.html'); ?> element to work for my headers and footers on the website, and they just will not work. I have changed my index file to .php and all of the files that I use that were .html before are .php. I even used the alternate SSI method, but it didn't work, and I didn't want to use SSI, because I like PHP more anyway. This is my code:


<? php include("/includes/header.html"); ?>

Content... //The page is named articles.php
</div>
</div>
</div>

<? php include("/includes/footer.html"); ?>

I figured that putting in the </div> tags might be important for some reason, I don't really know. Is there ANYTHING wrong with the code?

ViciousJ

6:05 am on Jul 10, 2009 (gmt 0)

10+ Year Member



I also tried that trick with the .htaccess where you make it so that the files can be read as .html instead of .php and it just screwed up my servers and I got a 500 Error on every page.

coopster

1:36 pm on Jul 10, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Is there ANYTHING wrong with the code?

Syntax? Remove the space in your php block declaration:

Incorrect: <? php 
Correct: <?php

ViciousJ

2:12 pm on Jul 10, 2009 (gmt 0)

10+ Year Member



Yeah, I'm new with PHP and I'm still getting used to all of that.

And I fixed that, but there's still a problem.

Let me also say that whenever I try to put the URL for the page in my address bar I always get a 500 Internal Server Error.

coopster

2:19 pm on Jul 10, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Check your logs then, something must be mis-configured and your logs will direct you to the issue.

ViciousJ

3:06 pm on Jul 10, 2009 (gmt 0)

10+ Year Member



Thanks a lot! I'm sure that's the problem...now I just need to find these logs...

ViciousJ

3:54 pm on Jul 10, 2009 (gmt 0)

10+ Year Member



Okay, actually, after reviewing the error logs...it says nothing about the 500 Error.

It says,"PHP Warning: MAX_FILE_SIZE of 10000 bytes exceeded - file"

And it is 3.86KB, but then I changed the file, and made it only 586 bytes, and it still gave me the 500 Error...I have no idea what's going on.

suplilumas

7:23 am on Jul 11, 2009 (gmt 0)

10+ Year Member



<?php include '/includes/header.html'; ?>
try this or try it with full file path

ViciousJ

1:07 am on Jul 13, 2009 (gmt 0)

10+ Year Member



That doesn't work either...I have NO idea what's wrong, I have tried almost anything that I can think of. I even just put the include element with a small amount of text and the text is just NOT there after the include element is there. And text doesn't show up even before the include element.

When I upload the .php file to my File Manager it shows that the file is broken or something. What could that mean?

idfer

1:50 am on Jul 13, 2009 (gmt 0)

10+ Year Member



Sounds like PHP can't find the file and error reporting is off or filters warning messages, so you're not seeing the error. Add this to the beginning of your script and give it a go:

error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 'stdout');

Also, make sure the path is correct. The included file's path is relative to your file system, it doesn't go through the web server to fetch its contents. So if your filepath is really '/includes/header.html', then PHP will look for it in the includes folder/directory at the root of your filesystem, i'm guessing more likely you want to use a relative path like 'includes/header.html' (without the starting / ) or something like '/path/to/document/root/includes/header.html'.

rainborick

1:53 am on Jul 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Keep in mind that, as referred to above, the include() function takes a path that is relative to the current document. So when you begin a path with a leading '/', it starts looking at (essentially) the server root directory, not your website's base directory on the server. So, you might well need a relative path like:

<?php include 'includes/header.html'; ?>

or

<?php include '../includes/header.html'; ?>

ViciousJ

2:55 am on Jul 13, 2009 (gmt 0)

10+ Year Member



The .php page says...


The server encountered an unexpected condition which prevented it from fulfilling the request.
The script had an error or it did not produce any output. If there was an error, you should be able to see it in the error log.

And also, my code says...

index.php


<html>
<body>
<p>Blah</p>

<?php include '../includes/full.html'; ?>

<p>This is my home page that uses a common menu to save me time when I add
new pages to my website!</p>
</body>
</html>

full.html


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Untitled document</title>
</head>
<body>
<p><a href="http://www.example.com/index.php">Home</a> - <a href="http://www.example.com/about.php">About Us</a> - <a href="http://www.example.com/links.php">Links</a> - <a href="http://www.example.com/contact.php">Contact Us</a></p>
</body>
</html>

coopster

12:47 pm on Jul 13, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are trying to include a full html document inside another html block of code. Trim back one or the other so only the portion you want is included.