PHP code on .html page

I have some php code on my index.html page and the code that should be running is not.

What am I doing wrong?  If I rename my page index.php the PHP code runs fine.  Shouldn't I be able to run the PHP code on the page with the .html extension?

HELP!
biffsmithAsked:
Who is Participating?
 
PromethylConnect With a Mentor Commented:
Or you could use

<Files index.html>
ForceType application/x-httpd-php
</Files>
0
 
BatalfConnect With a Mentor Commented:
No, the web server setup determines whether .html files will be parsed by PHP or not.

If you're using Apache webserver, you have to open httpd.conf and put in a line like this:

AddType application/x-httpd-php .html

Then the webserver needs to be restarted.
0
 
ziffgoneCommented:
Promethyl's solution should work, but he/she wasn't clear on what it is, if you're unfamiliar.

Create a new text document and copy & paste his code into it:

<Files index.html>
ForceType application/x-httpd-php
</Files>

The save this file as ".htaccess", like a file extension without the file name. Upload this file into your main directory where index.html resides. That should do it.

Regards...
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
PromethylCommented:
heh. I do that a lot. Just tell people what to do and not tell them why. It's a carryover from my day job. =)
0
 
Codeit1978Commented:
here is a good soultion.

Your web server looks at index.html index.htm so on and so fourth.
if you have a index.php and remove your index.html, it will look at that page first.

So if users type in yourdomainname.com  it will load your only index page, being your index.php.
0
 
Codeit1978Commented:
Also just on a note.  HTML code is rendered by the browser, scripting code is either complied or interperted by your web server :)
0
 
PromethylCommented:

>Also just on a note.  HTML code is rendered by the browser, scripting code is either complied or interperted by your web server :)

Incorrect.

Using the files directive causes the PHP code to be interpreted by the handler, in this case, PHP. PHP code is not handled on the same box, unless your webserver is local, but never by IE. In the event undhandled PHP code is sent to IE, it is treated as any other hTML tag, and not displayed outright, observable in the source.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.