Simple PHP Include isn't working ~


#1

Hey Folks,

I’m reasonably familiar with HTML, and brand new to PHP.

For now, I’m just wanting to use the PHP “include” function, but it doesn’t seem to be working.

Here’s a simple example of the problem:

http://www.kirtancentral.com/test.html

using <?php include("includes/test.php"); ?>

Dreamhost support recommended I use that exact formatting, featuring the relative URL, but I’ve also tested absolute URLs as well as single ’ instead of double "

You can see them all fail here:

http://www.kirtancentral.com/test2.html

Any thoughts?

Thanks!
~Daniel


#2

Since you’re “brand new” I’m going to assume you are on shared hosting and haven’t attempted to use the .htaccess or phprc files yet.

First of all, its not going to work in a file with the extension .html - you need to rename the files to have extension .php

Second, using include() with a URL is bad, so it is disabled. Instead of a URL, use a file system path to a local file instead. And having said that, you may need to specify the full path, i.e. /home/USERNAME/kirtancentral.com/includes/test.php - also see the $_SERVER[‘DOCUMENT_ROOT’] value.


#3

Ok, I tried it with test.php instead of .html, and now it works.

Is there no way to use php includes within a .html file?

Thanks,
Daniel
[hr]
Ah, got it, had to add this line to .htaccess:

AddType application/x-httpd-php5 .htm .html .php