Sunday, December 9, 2012

[Web] Render html files as php files

You have an html page and you have no access to server side code. But, since you're hosted on a server that supports php, why not render htm/html file extension with phpengine, so you can write php server side code?

Doing this is possible, but can be tricky, specially using third party hosting companies such as
First, you need to get them to enable the htaccess file that allows you to add web server rules. Then you need to use AddType to configure html mime types to be rendered as php.

- Retrieve .htacces file from the ftp server
- Rename or delete the .htaccess file from the ftp server (overwriting the existing one may not work)
- Configure your file for ASCII format, and add these lines:
Options +ExecCGI
AddType application/x-httpd-php5-3 .htm .php
AddHandler x-httpd-php5-3 .htm .php

- Upload the .htaccess again, to the ftp server, and give it +777 permissions
- Use or create an html page with php code and watch it render

< ?php phpinfo(); ?>

No comments:

Post a Comment