Forum Moderators: coopster
<html><head><title>Calendar</title></head><body>Now, this file would normally have to be saved with a
<h1>Calendar</h1>
<p>
<?php include("myphpfile.php"); ?>
</p>
</body></html>
.phpfile extension. If not, and you saved it with a
.htmor
.htmlextension, when it hits the <?php ... ?> code block the HTTP server won't know what to do with it and will just print that part out on your page in text/html. Most web servers offer some nice modules that allow you to parse files with
.htmextensions as PHP though.
so i first have to change the .html file to a .php file, right?
Yes, that is the easiest route. If you truly want to keep the extension as .htm or .html we can address that, too. It will depend which HTTP Server you are using. For now, just change the extension to .php.
do i have to specify the path to the .php file that i want to display?
It all depends. I realize that's not the answer you are probably expecting so I'll explain a bit. Actually, maybe this recent thread in the PHP Forum will help...
include path error... [webmasterworld.com]
For some reason the one line didn't work for me, I had to use a little more. It's probably got more than what's needed, but I'm switching my sites to use all PHP includes wherever possible, and this is what's working perfectly for .html or .htm pages
AddType application/x-httpd-php .html .php .htm
AddHandler application/x-httpd-php .html .php .htm
That's with just cheap virtual hosting with Cpanel.
>>parse files with .htm extensions as PHP though.
Best thing since sliced bread, and it's a nice way to start to get over the "fear of PHP."
I presently use php includes in my html pages to access my shopping cart, and display certain things like a shopping cart search, cart contents, etc. on these pages.
I was thinking of just changing all the html files to .php extensions and forgetting about the includes.
Any advantage to doing this.....and yes, what about the search engines?
Thanks...
nuplus,
Once we are over that hump we can find out which HTTP Server you are using and offer extension solutions, including nifty tricks such as how to make a file with a
.htmextension get parsed by the PHP processor, all the time making it look like we are serving up a standard HTML page request rather than some fancy server-side processing going on.
As suggested, if you are using Apache and running PHP as a module, you will only need the AddType [httpd.apache.org] directive:
AddType application/x-httpd-php .php .htm .htmlThe AddHandler [httpd.apache.org] directive is a method used on servers running PHP as a CGI module. Why is it even necessary? It is the way the server is set up. Apache's mod_mime module explains that care should be taken when a file with multiple extensions gets associated with both a MIME-type and a handler. This will usually result in the request being by the module associated with the handler.