WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-14-2006, 11:52 AM
WebProWorld Member
 

Join Date: Aug 2004
Location: Indiana
Posts: 56
Bluevoodu RepRank 0
Default php in html?

I have a few old html sites that I am trying to get our php code into the html..

I've used the <script> method... and that doesn't seem to work.

Is it possible to use PHP within html? I've asked around, and a few people said it is possible, but no one knows how to do it. I've checked books, that W3 site, and a few other places. Nothing gives direct reference on how to do this.

heck... all I want to do is to include some "informational includes."


Thank you in advance for your help.
†B†V†
__________________
www.egameaddiction.com - Game Addiction
www.egameaddiction.com/forums - Video Game Forums
www.egameaddiction.com/store - Game Addiction: Online Video Game Store
Reply With Quote
  #2 (permalink)  
Old 02-14-2006, 05:39 PM
WebProWorld 1,000+ Club
WebProWorld Moderator
 

Join Date: May 2004
Location: Austin, TX
Posts: 1,330
jestep RepRank 0
Default

You cannot run php directly from an email.

The only way I could see doing it would be to put a frame or iframe in the email that links a page on your website.

Since an email message is downloaded onto and run directly from a computer, there is no way for the php in the message to be parsed. It would display as code only.

If you use a frame, the message would display the page on your website, where your web server parses the php.
Reply With Quote
  #3 (permalink)  
Old 02-14-2006, 05:43 PM
WebProWorld Pro
 

Join Date: Jul 2004
Location: Irvine, CA
Posts: 120
spenland RepRank 0
Default

What you need to do is place the code that you would like to include on a seperate page lets call it "test.php". Then simply use the following php script to place anything on that page into your current page:

<?php include('test.php'); ?>

I use this a lot when I have a header, footer, and sidebar that I want to include on every page. I would make sure the pages you include start with a <tr> and close with a </tr> then place the php include inline like this:

<tr>
<td height="88" colspan="2" valign="top">
<table width="100%" border="0">
<?php include('test.php'); ?>
</table>
</td>
</tr>

This way the table will always enclose your include.

Good luck
Reply With Quote
  #4 (permalink)  
Old 02-14-2006, 05:46 PM
Que Que is offline
WebProWorld New Member
 

Join Date: Sep 2003
Location: LA
Posts: 6
Que RepRank 0
Default Re: including PHP in an HTML file

The way I do it is to simply change the extension of the html file (.htm or .html) to .php. Then wherever I want to put PHP code, I encapsulate it like this <?php my..code..here ?>
Do not change anything else about your html document. ie. leave <html><head> etc... where they were. Wherever you put "<?php some..code ?>" the server will process it as PHP code.

So if your original document was called 'about.html' just change it, and any links to it, to 'about.php' and then add your code per above wherever you want.

Hope this helps
-=Randy
Reply With Quote
  #5 (permalink)  
Old 02-14-2006, 05:53 PM
WebProWorld 1,000+ Club
WebProWorld Moderator
 

Join Date: May 2004
Location: Austin, TX
Posts: 1,330
jestep RepRank 0
Default

Wow.

I completely misread your post and gave you an answer that related nothing to your question.

Sorry about that.


Basically, you need to tell your server to parse html as php.

You can do this with htaccess or in your httpd.conf file.

In htaccess or httpd.conf
Code:
AddType application/x-httpd-php .htm .html
After that you can use any php tag in any html page just like you would with a php page.
Reply With Quote
  #6 (permalink)  
Old 02-14-2006, 05:54 PM
WebProWorld New Member
 

Join Date: Jun 2003
Location: UK
Posts: 2
mbgj RepRank 0
Default

the simple answer is :
if you are on ..nix and apache make sure you have

AddHandler application/x-httpd-php .htm .html

in .htaccess
this forces htm html page to be raced through php

than anywhere in htm simply use open php (<?php) close php (?>)

<?php
echo "hello world";
?>

<?php
include "bitof code or tect.xxx";
?>

Simply anywhere header or body

etc etc
Expat
Reply With Quote
  #7 (permalink)  
Old 02-14-2006, 06:03 PM
DrTandem1's Avatar
WebProWorld 1,000+ Club
 

Join Date: Oct 2003
Location: Encinitas, CA
Posts: 1,908
DrTandem1 RepRank 2
Default

It depends what you are trying to do. If you need to run a script from the page, then the extension must be .php. Yes, there are different ways to accomplish this, using redirects or simply changing the extension from .html to .php. However, doing this will almost certainly run into SERP issues for a time.
__________________
DrTandem's San Diego Web Page Design, drtandem.com
Reply With Quote
  #8 (permalink)  
Old 02-14-2006, 06:27 PM
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Spain
Posts: 335
computergenius RepRank 1
Default Doesn't have to have a php extension

Your pages do not need to end in php - DONT change the page names, or you will have problems with search engines.

You have to tell your server to handle pages as though they were php pages, and not HTML.

As has been said, you need to change your setup, the simplest way being to change .htaccess

<?php include('test.php'); ?> will not work, because the page is not a php page!

Thats assuming that your server has php enabled. <G>
__________________
Pete Clark
Advertise events locally in Spain for free - http://hotcosta.com/events.php
Reply With Quote
  #9 (permalink)  
Old 02-14-2006, 07:11 PM
WebProWorld Pro
 

Join Date: Jul 2004
Location: Irvine, CA
Posts: 120
spenland RepRank 0
Default

oops yeah I forgot about the htaccess page. You definately need to edit that so embed php in html.
Reply With Quote
  #10 (permalink)  
Old 02-14-2006, 10:05 PM
incrediblehelp's Avatar
Moderator
WebProWorld Moderator
 

Join Date: Jan 2004
Location: Live in Cincy Now
Posts: 7,654
incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4incrediblehelp RepRank 4
Default

Quote:
Originally Posted by jestep
Wow.

I completely misread your post and gave you an answer that related nothing to your question.

Sorry about that.


Basically, you need to tell your server to parse html as php.

You can do this with htaccess or in your httpd.conf file.

In htaccess or httpd.conf
Code:
AddType application/x-httpd-php .htm .html
After that you can use any php tag in any html page just like you would with a php page.
Wouldnt this bog down the server?
Reply With Quote
  #11 (permalink)  
Old 02-15-2006, 04:42 AM
WebProWorld Member
 

Join Date: Mar 2004
Location: UK
Posts: 58
johnmcm RepRank 0
Default SERP don't care anymore

Just name the pages .php I have lots of sites in top ranking for hard terms like diamond engagement rings in top 10 Google, Yahoo, and msn and all the pages are .php

This is an old story which the search engines fixed:) They really will not discriminate;)
__________________
"Working it as we speak" www.gotum.com Designing the future today. Tomorrow if I'm real busy john7@gotum.com Newest site: www.loveti.co.uk
Reply With Quote
  #12 (permalink)  
Old 02-15-2006, 05:34 AM
Faglork's Avatar
WebProWorld Veteran
 

Join Date: Feb 2005
Location: Forchheim, Germany
Posts: 947
Faglork RepRank 0
Default

Quote:
Originally Posted by incrediblehelp
Wouldnt this bog down the server?
If you do it on a per-virtual-host base, no. For the server it makes no difference to parse a PHP file for code or a HTML file.

It would bog the server down if you would apply this to all virtual hosts (the whole server). In this case the server would parse *all* HTML files in all virtual hosts whether they contain PHP code or not.

But then again, so what? If all virtual hosts on that server would use PHP pages, the server would have to handle that ...

faglork
Reply With Quote
  #13 (permalink)  
Old 02-15-2006, 07:55 AM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 380
southplatte RepRank 1
Default

I think one of the main things missing here is the fact that the web server has to be PHP enabled in the first place or none of the suggestions listed will net any results other than errors.

To verify you have PHP available on your server, make an empyt document and put the following line in:

Code:
<?php echo phpinfo(); ?>
Then upload it to the server and load it in your browser. If it displays a page with info on it - you can then use the .htaccess or add handler methods mentioned previously to have your server parse the PHP code you wish to use.

If you have good search rankings DO NOT change the names of your files to end with .php - use the handler method for the httpd.conf file as mentioned and tell it to parse .htm .html .php as PHP files. This will keep the same pages names that the search engines currently have indexed, however the PHP content will be executed at that point then.
Reply With Quote
  #14 (permalink)  
Old 02-15-2006, 10:29 AM
DrTandem1's Avatar
WebProWorld 1,000+ Club
 

Join Date: Oct 2003
Location: Encinitas, CA
Posts: 1,908
DrTandem1 RepRank 2
Default

Also, some hosts do not allow the .htaccess file to be modified.
__________________
DrTandem's San Diego Web Page Design, drtandem.com
Reply With Quote
  #15 (permalink)  
Old 02-15-2006, 10:48 AM
WebProWorld 1,000+ Club
WebProWorld Moderator
 

Join Date: May 2004
Location: Austin, TX
Posts: 1,330
jestep RepRank 0
Default

To sum it all up:

1. Make sure you server can run php:
Quote:
Originally Posted by southplatte
To verify you have PHP available on your server, make an empyt document and put the following line in:

Code:
Code: 
<?php echo phpinfo(); ?>
Then upload it to the server and load it in your browser.
2. Make sure your server will run htaccess.

To do this either make an htaccess file with the correct code in it and try or ask your server admin.

If you get an error 500, or it just doesn't work, then you may have problems.

3. Upload your .htaccess file to the root directory. Also for some servers this directory is one above your main www directory.

Code:
AddType application/x-httpd-php .htm .html 

or some servers may require:
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .html
Upload and restart apache. If you are on a shared server, this may be the hard part.

As far as slowing the server down. It will only slow it down as much as if your pages were php instead of html. Also as states, if you do it on a virtual host basis with htaccess it will only affect the site it is being used on.
Reply With Quote
  #16 (permalink)  
Old 02-15-2006, 10:21 PM
WebProWorld Member
 

Join Date: Aug 2004
Location: Indiana
Posts: 56
Bluevoodu RepRank 0
Default

there seems to be some questions or spots that need clarity.... I am editing my original post right now to let everyone know my "website" situation and how I am hosted.. hopefully this will help.

thank you all for your replies.

Update:
Guess I cannot update my original post... so my update will go here.

I have a dedicated server hosted with hostway. I have access to my .htaccess... I can add more to any folder I wish. I have php, and many other things enabled on the server. I use php pages....

but what I was really trying to do was... I have quite a few include pages (.php pages) that I use. I have some old html pages that are still used. I want to include the .php pages in the .html pages. I've tried many methods of doing this.... inside and outside of frontpage 2003 and nothing has worked. It just displays the code (won't run the code).

Any suggestions made... cannot bog down the server. I have very good load times on my site for every page... and load times and over all site load cannot be effected SIGNIFICANTLY. If it is going to slow down the site, I won't do it.

Would the .htaccess method be the way to go here?

thank you again for your time.
†B†V†[/b]
__________________
www.egameaddiction.com - Game Addiction
www.egameaddiction.com/forums - Video Game Forums
www.egameaddiction.com/store - Game Addiction: Online Video Game Store
Reply With Quote
  #17 (permalink)  
Old 02-15-2006, 10:39 PM
WebProWorld 1,000+ Club
 

Join Date: Jul 2003
Location: Toronto, Canada
Posts: 2,193
cyanide RepRank 0
Default

Try putting the following code in htaccess of your root directory

Code:
AddType application/x-httpd-php .htm .html
This will allow html pages render php code
__________________
|
Web Hosting Guru
| Need Help For Your Forum?
Reply With Quote
  #18 (permalink)  
Old 02-16-2006, 03:40 AM
Faglork's Avatar
WebProWorld Veteran
 

Join Date: Feb 2005
Location: Forchheim, Germany
Posts: 947
Faglork RepRank 0
Default

Quote:
Originally Posted by Bluevoodu
Any suggestions made... cannot bog down the server. I have very good load times on my site for every page... and load times and over all site load cannot be effected SIGNIFICANTLY. If it is going to slow down the site, I won't do it.

Would the .htaccess method be the way to go here?
I don't see a chance to bog down the server, especially because you have a dedicated server. As I said, for the server it is irrelevant WHAT it parses. Since you are already using PHP, some pages more to process won't result in heavier server load.

The whole server load discussion would only matter if
- you have hundreds of huge static HTML-based sites on that server
- you change the config for the whole server

In this scenario, the server would suddenly have to parse thousands of pages more. This *may* slow down a weak server.

Under normal circumstances, forget the server load issue.

faglork
Reply With Quote
  #19 (permalink)  
Old 02-16-2006, 02:29 PM
WebProWorld 1,000+ Club
WebProWorld Moderator
 

Join Date: May 2004
Location: Austin, TX
Posts: 1,330
jestep RepRank 0
Default

Quote:
I don't see a chance to bog down the server, especially because you have a dedicated server. As I said, for the server it is irrelevant WHAT it parses. Since you are already using PHP, some pages more to process won't result in heavier server load.

The whole server load discussion would only matter if
- you have hundreds of huge static HTML-based sites on that server
- you change the config for the whole server

In this scenario, the server would suddenly have to parse thousands of pages more. This *may* slow down a weak server.

Under normal circumstances, forget the server load issue.
I completely agree. The effect on loading speed is going to be negligible unless you are talking about a lot of traffic on a lot of html pages, all at the same time.

Unless your server is absolutely a piece of trash, it is very unlikely that you or your visitors will notice any difference at all.

Once you get the htaccess taken care of, any standard php include should work fine.

include
include_once
require
etc...
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0