We know that php script can't be executed unless two conditions:
-Must be in a php file.
-Must be between the tags <?php and ?>
But today we will talk about a great solution; you will learn how to put php script in html file.
This is very helpful if you don't want to rename your pages from html or htm extension to php and update all links to it...
The solution is very easy, but to understand it you need to know how php works in server. In apache server, every time a visitor load a file with php extension, the server will ask php to work on it.
We now will ask apache server to execute .html file like .php file , so the server will see .html files like as .php files.
The first step, create .htaccess file in your document root, and if it already exist open it and go to it's end.
In the .htaccess file, add this line and save it:
AddType application/x-httpd-php .html
This will make html page executed as php files.
If you want to add new extension, just add it to this line, like that:
AddType application/x-httpd-php .html .htm
No all is done, you can put your php script in html files ! Enjoy !