Welcome to WebmasterWorld Guest from 54.196.147.57

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Can I run PHP inside a .html file?

     

brucec

6:45 pm on May 26, 2004 (gmt 0)

10+ Year Member



I know that a PHP file needs a .PHP extension, but my web logs tell me that customers are landing on an HTML file and I would love to access my MySQL database from there?

Can this be done?

bhartzer

6:48 pm on May 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can parse your html pages as PHP. Use .htaccess to do it.

dcrombie

6:51 pm on May 26, 2004 (gmt 0)



Yes, there are literally hundreds of threads on this topic - you can use the site search to find them.

Look for "php addtype".

somerset

9:28 pm on May 26, 2004 (gmt 0)

10+ Year Member



if you have server side includes turned on, use an include call to a php file:

<!--#include virtual="myfile.php" -->

You can include any scripting processing in the php file. The server completes any server side scripting (database calls etc) in the php file before it is called into your .html file.

henry0

11:56 am on May 27, 2004 (gmt 0)

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



include virtual won't work if the page has an extension of " .html"
(at least on my servers)
using include virtual calls for an extension of:
" .SHTML"

brucec

2:34 pm on May 27, 2004 (gmt 0)

10+ Year Member



I thought SHTML files work for CGI. I will try the include method. I use tons of includes in my PHPs, but never in my HTMl. I will have to change that habit!

Thanks everybody.

If you have anymore suggestions, please don't hesitate to throw them in here.

ProductivePC

6:40 am on May 30, 2004 (gmt 0)

10+ Year Member



There are a few different ways to include php into an HTML document.

1. If you have available to you cpanel or the windows equivalent then you can simply turn on SSI, add .htm and .html to your list and begin to include SSI's within your html pages.
<!--#include virtual="myfile.php" -->

2. You can reference a small javascript
<script language="javaScript" src="myfile.php"></script>
Do note that the "type" has been left out on purpose.
Using the method you will also have to modify your echo statments as well. Sometimes they have a funny effect if you don't break them up. If you don't have any problems then don't fix it... if you start to have problems then look at your echo statements

3. This is just the opposite....
If you want to send information to a php file such as the title of the webpage
You can utilize the following method

<script language="JavaScript">
var image = "../pixel.gif";
var title = escape(document.title);
var link = "<img src='../myphpfile.php?title=" + title + "&img=" + image + "' align='middle' style='display:none' alt='&copy;0'>";
document.write(link); //This will write out to the page
</script>

Now on your PHP page you include the following:
$title = $_GET['title']

That will transfer the information from JavaScripting via the URL to the PHP page and now you can do what you want with it via PHP.

Hope it helps

Wayne

[edited by: jatar_k at 3:48 pm (utc) on May 30, 2004]
[edit reason] no sigs thanks [/edit]

ogletree

7:18 am on May 30, 2004 (gmt 0)

WebmasterWorld Senior Member ogletree is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I want to use a normal include statement but I want to use .html files. How can I change my .htaccess file to do this?

corz

9:30 am on May 30, 2004 (gmt 0)

10+ Year Member



see [webmasterworld.com ]

;o)
(or

[edited by: corz at 9:32 am (utc) on May 30, 2004]

somerset

9:31 am on May 30, 2004 (gmt 0)

10+ Year Member



henry0 / ogletree

Your include statement is only working on shtml files because your .htaccess file (if you are allowed to use one) needs to be altered. Here is a sample .htaccess file command to allow includes for .htm .html and .shtml

AddType text/x-server-parsed-html .shtml .html .htm

Other unrelated uses for this .htaccess file may be as follows:

ErrorDocument 404 [mydomain.co.uk...]

this gives a smooth 404 redirect, also if your home page does not happen to be a default one, use this:

DirectoryIndex myfile.php

There are other commands you can add to the .htaccess file including modrewrite statements. Below is a compilation of the ones above which can be pasted into a text file, amended, and saved as .htaccess and tried:

AddType text/x-server-parsed-html .shtml .html .htm
ErrorDocument 404 [mydomain.co.uk...]
DirectoryIndex myfile.php

ogletree

9:36 am on May 30, 2004 (gmt 0)

WebmasterWorld Senior Member ogletree is a WebmasterWorld Top Contributor of All Time 10+ Year Member



That is just too cool thank you.

[edited by: ogletree at 9:41 am (utc) on May 30, 2004]

t34WRJ

9:38 am on May 30, 2004 (gmt 0)

10+ Year Member



Add this to the .htaccess file in the directory that you want your html files to act like php files:

AddType application/x-httpd-php .html

Cheers

James

 

Featured Threads

Hot Threads This Week

Hot Threads This Month