0

How can we include a php file into a html file?

I know we can do this with:

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

but I don't have access to the server. Any other solution which I can include in my website folder or file?

2
  • @air: What do you mean by 'include'? As in like server-side include? Commented Oct 17, 2009 at 8:54
  • Perhaps you can ask your host if they will add that line? It's a long shot but worth it. Commented Oct 18, 2009 at 14:09

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

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> 

2 Comments

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 ?
No, this is for Apache. It's useful to state such things in the question.
1

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.

Comments

0

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.

2 Comments

uhm, what? php will always contain html code, that's what is was developed for
@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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.