Forum Moderators: coopster

Message Too Old, No Replies

How to get PHP into HTML files - FrontPage

Trying to create HTML files with PHP includes

         

katynewweb

12:52 am on Sep 26, 2006 (gmt 0)

10+ Year Member



I am new to the PHP world, and want to know if it is possible to create a page with an HTML extension that contains a PHP include statement in it.

I can get the PHP include to work correctly when I name the page it is on with a PHP extension, however, I would like to be able to create that same page with the include statment with an HTML extension.

Is this posible? If so, anything special to get it to work?

FYI - FrontPage 2003 uaser.

Thanks!

eelixduppy

1:01 am on Sep 26, 2006 (gmt 0)



You have to edit your httpd.conf file so that Apache parses .html files as php. Add this line to your httpd.conf file, where you have the other AddType statements:

AddType application/x-httpd-php .html

Although this isn't really recommended unless absolutely necessary. If you add this, all your html pages will be parsed as if they are php, which will reduce efficiency, and is overall not a great idea. Anyway, good luck!

You are better off just changing the extension of whatever file you are using to '.php'.

katynewweb

1:17 am on Sep 26, 2006 (gmt 0)

10+ Year Member



I am trying to make the web site easier to update by using basic include statments for the header, navigaiton and footer.

On the HTML pages where the banner and navigation used to sit, I have "include PHP" statments referencing PHP pages I have on my server.

Is there a way to get the PHP code to work on the files that have HTML extensions?

I have several pages that are over a year old that have html extensions and have been already crawled by the search engines.

Since I have ranking in the search engines the way the pages are named already, I would prefer to not have to rename them with a PHP extensions.

lmo4103

2:31 am on Sep 26, 2006 (gmt 0)

10+ Year Member



I thought you could do:

<html>
<body>
.
.
.
<?php
include ("me.xyz");
?>
.
.
.
</body>
</html>

I guess not without above httpd.conf.

>>Since I have ranking in the search engines the way the pages are named already, I would prefer to not have to rename them with a PHP extensions.<<

Search about "supplemental results" before you rename any files.
Rankings may be at risk.

[edited by: lmo4103 at 2:59 am (utc) on Sep. 26, 2006]

eelixduppy

2:53 am on Sep 26, 2006 (gmt 0)



>>> I thought you could do:

lmo4103,

You can, but only if that file you have that in is parsed as PHP. You can have HTML files also parsed as PHP, only if you change your config file as shown above. I hope I have made this understandable.

katynewweb, read my first post.

Best of luck!

Arctrust

4:09 am on Sep 26, 2006 (gmt 0)

10+ Year Member



I think what the question is....

Can an HTML page created in FrontPage have a PHP include...

If that is the question...I am having the same problem.

I have HTML pages and want to include an INCLUDE PHP in the header portion of the page and when I upload the HTML page to my server, nothing comes over where I have the PHP code.

If I change my ENTIRE page to a PHP extension then my PHP code comes over.

Is this a Front Page problem? What am I doing wrong in Front Page?

Thanks guys!
ARC

jimbeetle

4:25 am on Sep 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am trying to make the web site easier to update by using basic include statments for the header, navigaiton and footer.

Well, if it's a Frontpage web, then that functionality is already built in.

You can include headers, footers, and left and right sidebars one of two ways, either using the "border" or "include page" functions. The latter is preferable as it seems to be a bit more robust than the border function.

You can also use the include page function for any repeated content on any area of the pages.

But, I'd suggest backing all the way up and cracking open a book to find out exactly what the program can do before trying to reinvent the wheel by mixing and matching technologies. There are a heck of a lot of features and from your post it's kind of apparent that you haven't as yet scratched the surface. Frontpage's templating ability might be of interest for ease of maintenance.

If there are reasons that you must use PHP and are on an Apache server, then follow eelixduppy's above advice (or if you don't have access to the httpd.conf file, then find out how to do the same thing in .htaccess), and also look into PHP Rocket for Frontpage.

phparion

12:05 pm on Sep 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you can use .htaccess file to parse .html as .php hidden.. and the one solution i can think of is to use frames and set the php page as initial page of the frame..

but you know what.. I HATE FRAMES :)

lmo4103

12:55 pm on Sep 26, 2006 (gmt 0)

10+ Year Member



Possibly, use .htaccess to redirect foobar.html to foobar.php with a 301 Status.
That way, the .html name that is indexed still winds up fetching the .php name and the robots are given the clue that the page has moved permanently.

Caution though that rankings may have a duldrum period while the robot's eyes are spinning around in its head.
One suggestion might be to try it on a few pages at a time and allow sufficient time to see how they perform before dumping the rest of the batch in.

My vote is for eelixduppy solution [webmasterworld.com]

spinnercee

1:38 pm on Sep 26, 2006 (gmt 0)

10+ Year Member



There's more than one way to skin your cat...

The easiest way to insert PHP script output into ANY web page is to have the script return a JavaScript document.write() write command containing the HTML you want on the page.

The PHP generates the HTML, and is called from the HTML page with a SCRIPT SRC="script.php" tag. The webserver serving the main HTML page does not have to know anything about (read that support) PHP because the client will actually call the PHP script from the server that does.

This is useful and powerful because it allows you host the PHP on a site that can do PHP (fully, ie. allowing fsockopen(), etc...), and use the script on ANY HTML page whether the host server supports PHP or not.

With respect to FrontPage and other HTML editors, just simply add the JavaScript tags for the PHP script.