[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

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!
0
biffsmith
Asked:
biffsmith
2 Solutions
 
BatalfCommented:
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
 
PromethylCommented:
Or you could use

<Files index.html>
ForceType application/x-httpd-php
</Files>
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now