Web Hosting Talk







View Full Version : PHP include frustration and questions


tonomud
02-04-2003, 06:45 PM
OK, first let me say that I'm not a PHP programmer. I'm going to learn, but I'm trying to fiddle around with a couple things while I'm waiting for the book to arrive.

I'm developing a decent-sized site, and I'm looking to use some sort of include for my header, footer, and navigation. I've been doing some research around the net regarding that as well. It seems that there are a couple of options: PHP and SSI. I've done server side includes before, but since I'm hoping to learn PHP, I thought I'd give that a try.

OK, I'm able to get a plain text .txt file to include. My navigation element is an .html file generated by ImageReady (uses javascript). And my header is a plain old .jpg. So I'm having some problems with the navigation and .jpg header.

For the .jpg, I get a parse error. For the navigation, the .html file is parsed, but all of the images are displayed as broken. I am able to load the navigation .html by itself by typing in its address, and it displays correctly.

What might I be doing wrong? Here's the code for the .html navigation. The "include" inside the include tag is the name of the directory that I'm using to test this out.
<?php include('include/navigation/site_navigation.html'); ?>

the other include tags are identical, with the only exception the changed filenames.

Here is the address, if you want to see for yourself. Keep in mind that I haven't even touched the design on this page, I just stuck the includes in a table to see if I could get them to work.
http://www.eriehouse.org/new/
Thanks!

MarkIL
02-04-2003, 07:12 PM
To actualy use images, you should specify an img tag. PHP's include() call will try to *parse* and *interpret* the file as a PHP script.

As for the images appearing broken -- make sure you either specify the absolute path to them or use a base tag.

(They don't exist in /new/images/, which is the path the page refers to.)

vSector
02-05-2003, 02:38 AM
The way i create my websites is always by using the following format


<?
include "/path/to/common.php";

$page_title = "";
$page_keywords = "";
$page_description = "";

include "/path/to/header.php";
?>

<!-- main content -->

<? include "/path/to/footer.php"; ?>

Rich2k
02-05-2003, 05:38 AM
That's the sort of thing I do.

Set the title and such seperately as variables then require the header template below it.

I usually seperate the <head> from the <body> as it allows you to put extra head content unique to an individual page.

On my site for instance the section is defined by a variable and the images, nav bar and titles change depending on what you set the variable to.