Run PHP From HTML - .HTML As .PHP - Execute PHP in

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

19/05/12

Run PHP from HTML - .html as .php - Execute PHP in .html

PHP / MySQL
Execute PHP from a .html File
By Angela Bradley, About.com Guide

How can I execute PHP code on my existing myfile.html page?: When a web page is accessed, the server checks the extension to know how to handle the page. Generally speaking if it sees a .htm or .html file, it sends it right to the browser because it doesn't have anything to process on the server. If it sees a .php extension (or .shtml, or .asp, etc), it knows that it needs to execute the appropriate code before passing it along to the browser. Here is the problem: You find the perfect script, and you want to run it on your site, but you need to included PHP on your page for it to work. You could just rename your pages to yourpage.php instead of yourpage.html, but you already have incoming links or search engine ranking so you don't want to change the file name. What can you do? First let me preface this by saying that if you are creating a new file anyway, you may as well use .php. This is to help people who have existing .html pages they need to execute PHP on. The way to execute PHP on a .html page is to modify your .htaccess file. This file may be hidden, so depending upon your FTP program you may have to modify some settings to see it. Then you just need to add this line for .html: Adyeapiainxhtdpp.tl dTp plcto/-tp-h hm Or for .htm Adyeapiainxhtdpp.t dTp plcto/-tp-h hm If you only plan on including the PHP on one page, it is better to setup this way: <ie yupg.tl Fls oraehm> Adyeapiainxhtdpp.tl dTp plcto/-tp-h hm <Fls /ie> This code will only make the PHP executable on the yourpage.html file, and not on all of your html pages. Things to watch out for: If you have an existing .htaccess file, add this to it, do not overwrite it or other settings may stop working! Always be very careful with your .htaccess file and ask your host if you need help Anything in your .html files that starts with <? will now be executed as PHP, so if it's in your file for some other reason (an XML tag for example 1 ) you will need to echo 2 these lines to prevent errors. For example: <ppeh '?m vrin"."ecdn=IT-">;? ?h co <xl eso=10 noig"UF8?' >
This About.com page has been optimized for print. To view this page in its original form, please visit: http://php.about.com/od/advancedphp/p/html_php.htm 2012 About.com, Inc., a part of The New York Times Company. All rights reserved.

Links in this article: 1. http://pe rsonalwe b.about.com /od/basichtm l/a/409x htm l_2.htm ?te rm s=x m l+ve rsion+e ncoding 2. http://php.about.com /od/phpfunctions/g/php_e cho.htm

php.about.com/od/advancedphp/p/html_php.htm?p=1

1/1

You might also like