How to insert PHP code inside HTML pages

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 only one of these lines inside your .htaccess file, these are the most common lines, most servers work with one of the first 2:

AddType application/x-httpd-php htm html
AddType application/x-httpd-php .html .htm .php
AddHandler x-httpd-php .html .htm .cgi .php
AddType x-mapp-php4 .html .htm .php
AddHandler server-parsed .html .htm .php
AddType application/x-httpd-php4 .htm .html .php
AddHandler application/x-httpd-php5 .html .htm .php

Note: 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.

Share with Google Plus