Execute the PHP file from a. html file

Source: Internet
Author: User

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. 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. 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 need ded PHP on your page for it to work. you coshould 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. 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. html:

AddType application/x-httpd-php. htmlOr for. htm
AddType application/x-httpd-php. htmIf you only plan on including the PHP on one page, it is better to setup this way:
<Files yourpage.html> AddType application/x-httpd-php. html </Files> 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:

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) you will need to echo these lines to prevent errors. For example:
<? Php echo '<? Xml version = "1.0" encoding = "IUTF-8"?> ';?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.