Forum Moderators: coopster

Message Too Old, No Replies

does a php "include" command work in a html file?

         

pelican

5:58 pm on Oct 6, 2003 (gmt 0)

10+ Year Member



Hi.
I'm in the process of updating my website and making parts more dynamic. Last night I was playing with adding a footer. This is what I inserted:

<?php

include ('./footer.inc');

?>

(and then I also created a footer.inc file in the same directory)

When I added this to the html file I was working on, it didn't work! However, when I changed that same file to .php instead of .html it did work. Now I know this has to do with parsing the file....but my php books all seemed to be saying I should be able to add the above to either a html file or a php file.

Could someone please tell me if it's possible to add this to a .html file and if so, what changes would I need to make? Can you think of any advantages or disadvantages to using a php or html file? The disadvantage for me would be I would need to change the name of every file on my site and I have good search engine rank and hesitate to do that.

Velmu

6:06 pm on Oct 6, 2003 (gmt 0)

10+ Year Member




To make your .htm or .html pages process like they were .php, just add this line to your .htaccess file:

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


[webmasterworld.com ]

pelican

12:43 am on Oct 7, 2003 (gmt 0)

10+ Year Member



Thank you Velmu! I will try that tonight.

Does anyone know if there are and advantages/disadvantages to using html or php files?

pelican

12:52 am on Oct 7, 2003 (gmt 0)

10+ Year Member



Well, I tried it but it did work....this is what I pasted into the .htaccess file:

ErrorDocument 404 [mysitedomain.com...]

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

and nothing else....is this correct?

Also, when I tried this using explorer it had no negative effect except it did not show the footer...however, when I tried it in Netscape and tried to pull up the pages, it instead wanted me to download them...weird :-)

RobinC

1:23 am on Oct 7, 2003 (gmt 0)

10+ Year Member



Just use -
include("footer.inc");
- the ./ isn't needed (and works well enough without here)...

Personally I just swapped over to using html extensions - simply to hide the fact I'm using php, which improves security as you're not giving away the technology behind your site, apart from that, I can't see any other reasons for it.

ergophobe

3:52 pm on Oct 7, 2003 (gmt 0)

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




Personally I just swapped over to using html extensions - simply to hide the fact I'm using php

Actually, even better is to avoid using extensions at all in your URL, since this makes it easier to have permanent URLs that don't change when technology changes.

See the article on Common HTTP Implementation Problems [w3.org] by the W3C, especially guideline 3 on Using Independent URIs [w3.org].

This article is an elaboration and extension of the famous article by Tim Berners-Lee, Cool URIs Don't Change [w3.org].

Since we're on the subject, I figured I might as well post some other resources, though these are general resources on URIs that don't necessarily talk about extensions:
[www-106.ibm.com ]
[alistapart.com ]
[alistapart.com ]
[useit.com ]

pelican

4:06 pm on Oct 7, 2003 (gmt 0)

10+ Year Member



Thanks guys, but I still can't even get it to work on my html files....don't know why....but now it SHOULD work so I just have to figure out what the problem is...

Robin, I'm actually using the full path...I just didn't want to post it to the board :-)

ergophobe

5:09 pm on Oct 7, 2003 (gmt 0)

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



Pelican,

What's your hosting situation? Do you have access to your php.ini file? If so, try putting the AddType command in there. It's possible that your .htaccess rights are limited (even if you are running the server yourself).

Tom

timster

8:56 pm on Oct 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just checking, are you restarting your Web server after making changes to .htacess?

Also if you add the line:
AddType application/x-httpd-php .html .php .htm

...to htaccess, but the line...

AddType application/x-httpd-php .php

...still appears there, that could be trouble. The first should replace the second.

dreamcatcher

10:40 pm on Oct 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another way you go is to use templates. Just a thought!

pelican

8:16 pm on Oct 9, 2003 (gmt 0)

10+ Year Member



Hi Guys,

The solution for me ended up being my hosting company adding:

AddHandler application/x-httpd-php .php .html

to the server config but not to the .htaccess file.

Thanks for all the suggestions and help!

sun818

9:35 pm on Oct 9, 2003 (gmt 0)

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



If your put PHP code is in a .html file, what will the end user see? The footer PHP code or the footer itself?

ergophobe

9:57 pm on Oct 9, 2003 (gmt 0)

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




If your put PHP code is in a .html file, what will the end user see? The footer PHP code or the footer itself?

If your server is set up to parse .html files as PHP pages (see previous posts on AddType), then it will be like any other .php page (i.e no PHP visible to user).

If it is set up to parse only .php files as PHP pages, then the user will in fact see PHP code and the HTML code you are trying to generate.

Tom

pelican

10:32 pm on Oct 9, 2003 (gmt 0)

10+ Year Member



Hi Guys,

I was mistaken before because I was looking at the .htaccess file for the whole site....it WAS added to the .htaccess file for that directory.

My little php script inside the html page is calling a .inc file with has text and html in it. That way, if I want to change stuff at the bottom of the page, I only have to change one file. If you do a view source, it only shows the html after the page has been parsed by the server.