Parsing PHP in HTML or HTM Files

·


I have a client with thousands of HTML files with contact form embedded to it. However it doesn’t have CAPTCHA function to prevent spam. A CAPTCHA (an acronym for “Completely Automatic Public Turing Test to Tell Computers and Humans Apart”) is a type of challenge-response test used in computing to determine whether or not the user is human. An example of CAPTCHA is like the image below. The numbers and letters are random each time you refresh the page.
Captcha on HTML

Now my client’s inbox is exploded with hundreds of spam emails everyday. To fix this problem, I have to include a new CAPTCHA function into the HTML files. Problem is, can HTML files parse PHP? Usually if you want to parse PHP codes, it will have to be .php extension for the webserver to identify that it’s a PHP file. So after added the CAPTCHA function, I have to rename all thousands of HTML files to PHP extension.

Thankfully I can save all the trouble of renaming thousands of HTML files to PHP by editing the .htaccess file. Here’s how I did it to parse PHP in HTML or HTM files.


Go to your WWW root, usually it looks like this:
path: /home/username/public_html

Look for the file named .htaccess. If it’s not there, create a blank page using NotePad and save it as .htaccess

Now edit this file by adding the following lines:

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

Save and close the .htaccess file. Upload it to your webserver (to your WWW root) and that’s it! Now your webserver will parse PHP codes even in HTML files!