Forum Moderators: coopster

Message Too Old, No Replies

html & php

displaying php page in an html page

         

nuplus

9:59 pm on Sep 13, 2004 (gmt 0)

10+ Year Member



i have an html page.

i want to display a calendar that i made in php in one section of a table on the html page. how do i call the php file to display the calendar in that one section?

coopster

10:15 pm on Sep 13, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Typically you parse the html page as PHP and simply use the PHP function include() [php.net] to include that chunk of PHP code. Take this file, for example:
<html><head><title>Calendar</title></head><body> 
<h1>Calendar</h1>
<p>
<?php include("myphpfile.php"); ?>
</p>
</body></html>
Now, this file would normally have to be saved with a
.php
file extension. If not, and you saved it with a
.htm
or
.html
extension, 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
.htm
extensions as PHP though.

nuplus

10:22 pm on Sep 13, 2004 (gmt 0)

10+ Year Member



so i first have to change the .html file to a .php file, right?

do i have to specify the path to the .php file that i want to display?

coopster

10:26 pm on Sep 13, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




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]

saoi_jp

3:49 am on Sep 14, 2004 (gmt 0)

10+ Year Member



Try this in your .htaccess file:


<Files yourpage.html>
ForceType application/x-httpd-php
</Files>

Put your page name where I wrote yourpage.html, and then you'll be able to use PHP on an html file.

Marcia

4:23 am on Sep 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I thought about doing it, but changing the file extensions means that it's all new pages to the search engines, and I saw one site change from .htm to .shtml and get into big problems with duplicates being picked up.

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."

tcustom

12:55 pm on Sep 14, 2004 (gmt 0)

10+ Year Member



I'm kinda in the same boat with all this.

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...

coopster

2:45 pm on Sep 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



OK, OK, I didn't want to throw the whole extension solution at nuplus this early. I wanted to make sure we have the includes working correctly, meaning a full understanding of the php include() [php.net] function itself as well as the include_path [php.net] configuration directive. This is going to be key in PHP development practices. Besides, learning and troubleshooting two issues at once only complicates things ;)

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

.htm
extension 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 .html
The 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.