Help - Search - Members - Calendar
Full Version: [MIX]How to replace PHP ext with HTML ?
MSFN Forums > Coding, Scripting and Servers > Web Development (HTML, Java, PHP, ASP, XML, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
pulkit
yes.gif Calling all webmasters and brains on buildtolearn :
I want to embed a PHP page / code in a .html page (html extension)
Pls tell me how to do it
Also i dont want to use the frame tag.
Basically i want to replace the php extension of a webpage with html


Pls help smile.gif
I need it
mattofak
Uh, do you have control over the server configuration...

for instance on Apache, you simply add a new AddHandler call to the Apache httpd.conf file... theres a lot online to do it with... just take a look around, with IIS, same kind of thing, but its more complicated, same story though, just look around for changing the handlers of files...
RayOK
this is somewhat simple.. actually, the first example here smile.gif

CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>php in html</title>
</head>
<body>

<?php
    print "hello! i work!";
?>

</body>
</html>
mattofak
unfortunatly, that wont work unless the server realizes it needs to process the page though the PHP preparser... you'll notice that that page still has a *.PHP extenstion, the question asked about PHP in a file with a *.HTML extension.
RayOK
I tested it on our apache server.. worked fine with the .html extension smile.gif
I think its the <?php ?> that tells the server to parse it as php
mattofak
Well, I dont know, I run Apache2 with PHP5, both using almost distro conf files, and it doesnt work for me...
RayOK
Ahh.. I see now. I spoke with my good buddy, the server admin, and he said its a setting in the Apache config file. Its "AddType application/x-httpd-php .php .php4 .php3 .phtml .html" Just add the extension to the list smile.gif
Rhelic
Yes, you just need to edit your Apache config file and add the .HTML extension to be passed to your PHP module.

But keep in mind this means EVERY .HTML on your site must pass through the PHP module, which slows your site down a little bit. If the site is very busy, this can become a problem but for the average website, it isn't.
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.