How to call PHP script within HTML files
When I ask you to listen
KafeInfo.com - bookmarking sosial Anda 
First off : Why the heck should you have/use PHP?
PHP is server side scripting. That means it is parsed on the server before your page loads in the browser. To the visitor and to the search engines PHP scripts are not noticeable. When PHP is combined with RSS feeds, links, blog entries, dynamic portfolio, it is a pretty powerful concept. With PHP you can add other people’s content to your web pages and the search engines will see it and think it is part of your website! (Think of the SEO-thingies). That PHP-parsed content when placed on your web page will essentially become a part of your web site and bring you more traffic. That is why most web developers recommend that you add the content from external sites to your website with PHP instead of Javascript.
Which comes first? Chicken or egg?
The characteristic of HTML that it will only parse / call the Javascript from within the HTML-parsing routine. (Okay, we both know it can call whatever files, but for the sake of this post, let’s pretend it’s that way, okay
). PHP, ASP, JSP, whatever, can call/use HTML tags/files, and not the other way around.
Yes, I know that you can simply “rewrite” everything into php and enclose the real php in <?php … ?>-tag.
But how should you do it if you insist that the file’s extension is still HTML and still can parse the PHP scripts inside? There are some ways:
- Option I
- a: .htaccess for HTM/HTML, IIS
- b: the same as Part I, only using the cPanel instead the hard way
- Option II: SSI Include
I. .htaccess (using notepad and ftp)
PHP scripts do not automatically work on html pages. If you have an HTML or (.HTM) based site, in order for PHP scripts to run on your .htm or .html pages you have a 2 options –the following is the option A: In order for a .html or .htm site to parse a PHP script on it’s pages, you need to have some instructions in your website’s .htaccess file. (For this step you will need access to the .htaccess file on your server.)
- Edit your .htaccess with AddType application/x-httpd-php .htm .html
Then Add the php code directly to your html pages- Then edit your .htaccess with either .htm server parsed .html server parsed OR Addhandler application/x-httpd-php .html .php
Then follow the directions below to use the php code with SSI Includes.
**NOTE 1:For Windows or IIS servers**
You do not have an .htaccess file. Windows IIS servers also cannot run php on html pages. Your only option for windows IIS servers is to use .shtml or .php pages with the php option from the reader. Or add Javascript to your html pages. For .shtml pages check your setup options and make sure the option for SSI includes is checked, then follow the directions below for creating the SSI include and file.**NOTE 2 : Explicit version number**
dedi_toblerone was kind enough to told me that you need to explicitly mention the PHP version.
So the code will look like this:
.htaccess: (the numbers indicates line numbers, no need to include it)
1: application/x-httpd-php .htm .html
2: .htm server parsed
3: .html server parsed
OR
3: Addhandler application/x-httpd-php5 .html .php
OR
3: AddType application/x-httpd-php5 .html .phpI. .htaccess (using cPanel) - Option B
In order for a .html or .htm site to parse a PHP script on it’s pages, you need to have some instructions in your website’s .htaccess file.
You can either manually modify the .htaccess file on your server (see option I-A), or if you have Cpanel, this can very easily be done using the ‘Apache Handler’ Function.
II. IIS Includes
SSI includes are short commands that reference another file on your server for inclusion on the web page where it is called from. Meaning you can put any information in an external file and remotely call it into any other page on your server with an SSI command. This is especially useful for making the task of editing large websites easier. When the file that is being included is changed, all of the pages that reference that file will change at the same time, without you having to change them all one by one.
SSI is also useful for parsing PHP scripts into .html or .htm webpages, since PHP by itself does not work on html sites. PHP code works on pages that have a .php extension. But instead of changing all of your webpages from .html or .htm to .php extensions, you can use SSI on your html pages.
The only thing that you need to do is include the following single line into the part where you want the PHP to be called:
<!–#include virtual=”/IWantToCallThisFile.php” –>
Closing words
This post is an excerpt from numerous websites and resources. And yes of course, there are still numerous ways to do this trick. Be so kind to post it on the comments box ![]()
When I ask you to listen
KafeInfo.com - bookmarking sosial Anda 











I have been looking for a way to do this for months. Thanks. I will definitely give it a try.
This is really great to know
sori lagi sempet mampir kang… hehehe…
semoga bermanfaat om…
^_^
Nice knowledge given. I understood well how to call php from another html.
get inbound links’s last blog post..How to get inbound links to improve page rank as well as search engine ranking?
how to add in Blogspot Blog
@siddiq: please elaborate what do you really want to add in blogspot?
That was a great article. It was complete. It helped me solve my buddies pblm. I have been trying with the option AddHandler application/x-httpd-php .htm .html but it did not work. But as per your instructions when I added the below two lines it started working. Thank you.
Addhandler application/x-httpd-php5 .html .php
AddType application/x-httpd-php5 .html .php
Lara’s last blog post..Most favourite Bharathiyar Kavithai
To do this in the .htacces file on cPanel apache servers you need to do this:
(Above your re-write rules)
#
# Run PHP scripts in HTML files.
#
AddHandler application/x-httpd-php .html
AddHandler application/x-httpd-php .htm
Make sure you refresh your cache before testing it.