Member Avatar for JayGeePee

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.

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.

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

Member Avatar for JayGeePee

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?

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.