954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP in HTML?

I was wondering how to display php on a html page? My site has a php backend doing all the work, html to make it look good. I'm trying to display a chat box which is coded in php on my html header page.

JayGeePee
Light Poster
47 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

I would recommend making the HTML file a PHP file and putting the php powered chat box where you need it, but if you insist on keeping it all HTML then I would make an iframe.

nquinlan
Newbie Poster
19 posts since Mar 2010
Reputation Points: 10
Solved Threads: 2
 

Or use URL Rewriting.

.htaccess

RewriteEngine On
RewriteRule (.*)\.html $1\.php [L]


This will make the browser think the document is .html but instead the server looks for .php.

PUBLIC URL: http://example.com/index.html
INTERNAL URL: DOCUMENT_ROOT/index.php

Froger93
Junior Poster in Training
74 posts since Sep 2009
Reputation Points: 11
Solved Threads: 6
 
I would recommend making the HTML file a PHP file and putting the php powered chat box where you need it, but if you insist on keeping it all HTML then I would make an iframe.

I tried the IFRAME... Everything worked fine, until I started the chat. The user function works, but when I type something the admin doesn't see anything. I rather not rename the extension.Or use URL Rewriting.

.htaccess
PHP Syntax (Toggle Plain Text)

1.
RewriteEngine On
2.
RewriteRule (.*)\.html $1\.php [L]

RewriteEngine On RewriteRule (.*)\.html $1\.php [L]

This will make the browser think the document is .html but instead the server looks for .php.

PUBLIC URL: http://example.com/index.html
INTERNAL URL: DOCUMENT_ROOT/index.php

Can I use this Rewrite Rule for just one page?

JayGeePee
Light Poster
47 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

Yes this should be in a .htaccess file by the way.

RewriteEngine On
RewriteRule ^chatpage\.html chatpage\.php [L]


Will work on the document named chatpage.php and you can access it by the chatpage.html.

Just change the chatpage on both sides for whatever you document name is.

Froger93
Junior Poster in Training
74 posts since Sep 2009
Reputation Points: 11
Solved Threads: 6
 

You could leave it as an html file, and make your html files parsable as php files (with addhandler in your .htaccess)

I would stay away form iframes wherever possible.

kylegetson
Junior Poster in Training
89 posts since Sep 2009
Reputation Points: 26
Solved Threads: 12
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: