How to insert PHP code in .html files

Normally you can only insert php code blocks into files ending in .php extension, by making some small modification you can also include php code inside html documents:

Create a blank file and call it .htaccess, you will need to upload this file on your server in the directory where you want to have .html pages containing php code or you can also place the .htaccess file in your site root, the settings inside it will apply to all its sub directories.

You need to type these lines inside your .htaccess file:

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

Note: Some servers might require that you use this line instead (it depends on server configuration):

  1. AddHandler x-httpd-php .html .htm .cgi .php
Note: GoDaddy.com shared servers need an hour before it can read a new .htaccess created on server, after that any changes inside .htaccess file are applied instantly.
Rate this content; the results will appear next to article links in site:
You need flash player