Php Code on html pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alsoto
Forum Newbie
Posts: 5
Joined: Tue Mar 20, 2012 8:38 am

Php Code on html pages

Post by alsoto »

How do I get my php code to run on html pages without a .php extension? I tried this but it doesn't work:



CODE for index.html

<html><head></head><body>

<?php include("test.php"); ?>

</body></html>

------------------------------------------------------------
test.php in same folder consists of the following text and nothing else: THIS IS DISPLAYING BECAUSE PHP IS WORKING!

------------------------------------------------------------
CODE for .htaccess in same folder:
AddType application/x-httpd-php .html .htm

------------------------------------------------------------
Firefox gives me: Download Error
C:\......Local\Temp\index-11.html could not be opened, beacuase the associated helper application does not exist. Change the association in your preferences.

Internet Explorer just gives me a blank page.


Thanks,
Al
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Php Code on html pages

Post by requinix »

Just to check the obvious first:

You're running these scripts in Apache, WAMP, or XAMPP? And the URL in the browser starts with "http://"? And the domain name is probably localhost?
alsoto
Forum Newbie
Posts: 5
Joined: Tue Mar 20, 2012 8:38 am

Re: Php Code on html pages

Post by alsoto »

cPanel Version 11.30.6 (build 4)
Theme x3
Apache version 2.2.22
PHP version 5.2.17
MySQL version 5.1.56
Architecture i686
Operating system linux
Dedicated IP Address 74.53.140.71
Path to sendmail /usr/sbin/sendmail
Path to Perl /usr/bin/perl
Perl version 5.8.8
Kernel version 2.6.38.7
cPanel Pro 1.0 (RC1)


http://www.ams007.com/newimage/index.html
JoeCommodore
Forum Newbie
Posts: 15
Joined: Fri Oct 01, 2010 10:16 pm

Re: Php Code on html pages

Post by JoeCommodore »

You need to set your apache (or other web server) handler to have PHP process the pages with .htm and .html... Something that could be answered with a google search or in the php installation and configuration forum. Though if you plan to distribute your scripts, I would advise not to do that.
alsoto
Forum Newbie
Posts: 5
Joined: Tue Mar 20, 2012 8:38 am

Re: Php Code on html pages

Post by alsoto »

in cpanel, is it in the section titled "Apache Handlers"?
irony09
Forum Newbie
Posts: 2
Joined: Sun Mar 25, 2012 9:48 am

Re: Php Code on html pages

Post by irony09 »

If all else fails or you are in a hurry, you could always use an iframe!
Post Reply