0

Is there a difference between saving your HTML files with PHP content as *.php files or as *.html files?

Frithjof
  • 2,083
  • 1
  • 12
  • 37

3 Answers3

2

Yes. Unless you've set your webserver up to serve html files through the PHP interpretor, these will never talk to PHP, which means it'll output raw PHP code.

By most default configurations

<div><?php echo 'test'; ?></div>

Would output the following:

PHP (.php and sometimes .php3/.php4/.php5/.phps):

<div>test</div>

HTML:

<div><?php echo 'test'; ?></div>

The HTML file will display as (empty) in your browser, but if you look at your source you can see the raw PHP code.

Community
  • 1
  • 1
h2ooooooo
  • 36,580
  • 8
  • 61
  • 97
1

It depends on the config of your web server, but generally speaking, yes there is: the default settings for most web servers means that a .php file will be processed as PHP, whereas a .html file will be sent directly to the browser without any processing.

You can change this behaviour if you really want to, but it's probably a bad idea.

If you're trying to make your URLs more "friendly" by doing this, then it's definitely not the best approach. It won't really change anything other than the file extension; you'll still have ugly URL parameters, etc that your users will see.

As an alternative, you may consider using URL rewriting (ie mod_rewrite) to convert "friendly" URLs entered by your users into .php URLs with URL parameters to be processed by your code.

Spudley
  • 157,081
  • 38
  • 222
  • 293
-1

you can't execute PHP code from an .html file

Savv
  • 435
  • 2
  • 7