Log in

View Full Version : How do we make html file with PHP?[ Question ]



www.webdevelopersahil.com
07-13-2013, 09:40 AM
Yes, how do we make html file with PHP? You may noticed that every mybb form has a thread with extension .html but according to me, to run php you should have .php extension and Mybb is also in php. How do they do it. Any suggestions? In simple words, how to run php coding in an HTML webpage?

djr33
07-13-2013, 09:56 AM
There are two ways:
1. Tell your webserver to run .html files through the .php parser. It won't hurt anything (because a normal .html page will just be output without doing anything to it, but now also any PHP will be executed), but it will slow your server a bit-- now every .html page is treated as a (slightly slower-- parsed) PHP page.

2. Use some kind of URL remapping so that when you get a request for .html you actually serve a .php file (behind the scenes; the user won't ever know).

Both are a little complicated but can be done using something like .htaccess, depending on your server's configuration. If you don't have full access to the server, it's possible you can't alter these settings.

www.webdevelopersahil.com
07-13-2013, 12:14 PM
I love complicated things :D thanks.

Beverleyh
07-13-2013, 12:46 PM
That was one thing that used to puzzle me when I got my first web hosting account because I'd read forum posts where people said that php scripts only worked on a php enabled host, in pages ending with the .php extension - except my scripts always worked fine in my .html pages without any intervention on my part. Anyway, when I started looking into .htaccess, I realised that my web host already provided this line in my .htaccess file;
AddType application/x-httpd-php .html .htmThat's when I realised what this line did - it was parsing PHP on .html/.htm pages. It was pretty convenient at the time, but as Dan already said, it makes the server work harder so those old pages are a little slower than newer ones ending .php