tags:

views:

227

answers:

4

how can we include php file into html file

i know we can do this with

                <AddType application/x-httpd-php .html>

but i don't have access to server... any other solution which i can include in my website folder or file.

Thanks

+4  A: 

Why not just rename the file to end in PHP? That would be the simplest way to do this.

Rich Bradshaw
While I think this is the right answer, he may not want to rename a bunch of links to point to foo.php instead of foo.html.
smack0007
+2  A: 

If you have access to your website folder, you could create a .htaccess file that includes:

<IfModule mod_mime.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php .html
</IfModule>

You could alternatively try:

<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>
Druid
yes i have access to my website folder... what name should i give to file... and i am on windows2003 server does this work for windows 2003 server ?
air
No, this is for Apache. It's useful to state such things in the question.
Rich Bradshaw
+1  A: 

Depending on what the code looks like that you want to include, and if you really have no other choice like the ones presented by Druid, you can use one of the following less-than-perfect embedding solutions:

  • An IFRAME with frameborder="0" pointing to the PHP script (Downside: dynamic resizing according to output size is possible only with JavaScript

  • An AJAX Snippet that loads the PHP file onLoad and injects the output into a DIV of your choice

  • A tag pointing to the PHP file. The PHP file must then issue JavaScript commands like "document.write()".

The IFRAME is the most fail-safe in the event the client has no JavaScript. The AJAX Snippet is the most elegant solution.

Pekka
A: 

The correct solution is not renaming it to .php. It is renaming to .phtml ;)

.phtml is the official file type for crossover files containing PHP and HTML code.

daemonfire300
uhm, what? php will always contain html code, that's what is was developed for
knittl
@knittl: Yes, that is what PHP *was* developed for. But now it is used in many different areas. Some companies I know use it in backend development to solve no html / web related business problems whatsoever.
Max
Downvote for a true answer... http://www.fileinfo.com/extension/phtml
daemonfire300