FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Parsing PHP in HTML





georgeodowd
Well, this is where I admit I'm rather new to all of this, but here's my conundrum:

I want to embed php in some of my html files just to recycle some code, but it isn't being parsed... the php tags are just displayed on the page. I've done some googling about this and suggestions ranged from adding a line to the .htaccess file (which didn't work) to changing settings in Apache (which doesn't apply, since I'm trying to host these pages via Frihost).

Is there any straight-forward way to do this?

Many thanks in advance.
badai
if you want to host it here, maybe you should just upload it and see if it work.
Fire Boar
PHP is only parsed in PHP pages and those included or required by a PHP script. Therefore, you need to use the .php extension for such pages.
rvec
Fire Boar wrote:
PHP is only parsed in PHP pages and those included or required by a PHP script. Therefore, you need to use the .php extension for such pages.
Not sure if you meant this, but those included pages also have to be .php pages. Including a .html page won't make it parse the code.
sonam
If you want include html tags and parse it then you can use .txt file extension. Including .txt files in php results with displaying html. Even more, you can put some php inline script betveen and get result like php. Simple example for e.g. include.txt:

Code:
<html>
<head>
<title>TXT INCLUDE EXAMPLE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1>This is included file...</h1>
<?php echo "<h2>...and this is PHP echo!</h2>"; ?>
</body>
</html>

Sonam
georgeodowd
rvec wrote:
Fire Boar wrote:
PHP is only parsed in PHP pages and those included or required by a PHP script. Therefore, you need to use the .php extension for such pages.
Not sure if you meant this, but those included pages also have to be .php pages. Including a .html page won't make it parse the code.


Do you mean this to apply just in the case of pages hosted by Frihost? If you mean in general, I'm not sure I agree, as we do this all the time at my work. I work on php embedded in html files on a daily basis, but not having set up the original infrastructure of the site, I'm not sure what it does to allow this.

Here's a pretty basic description of how it should work: http://www.desilva.biz/php/phpinhtml.html
But, of course, it does not for me, which is why I'm posting here.
rvec
you do that at work Shocked eehw
I hope you also provide a hosting account, cause that won't work on all hosting providers. I don't know how frihost handles it, but if I where you I'd rather batch rename files instead of adding that .htaccess file to the root.

edit: http://www.stintercorp.com/br.php
try that instead of a .htaccess, it's much cleaner.
georgeodowd
rvec wrote:
you do that at work Shocked eehw
I hope you also provide a hosting account, cause that won't work on all hosting providers. I don't know how frihost handles it, but if I where you I'd rather batch rename files instead of adding that .htaccess file to the root.

edit: http://www.stintercorp.com/br.php
try that instead of a .htaccess, it's much cleaner.


OK, sorry, now I'm confused. What I meant is we embed php inside html files - I don't think we actually use an .htaccess to make this work. In fact, I have no idea what we do (which is why I'm going to go ask Smile ).

For my personal website, having to rename the files isn't the issue, since I'm only currently working on three of them. I just wanted to - for hidebound reasons - keep my work inside html files, instead of php files. I prefer to keep a split between html files which generate page content and php files which contain only classes of functions. I guess I'll do some more digging and see how things are done at work...
Thanks for the help!
SonLight
Apache (or other web servers) can be set up to interpret any extension as php if desired. Some sites do parse all html files as php, which is fine, but it means that if you have a lot of static html files, they will slow down the server because they are parsed as php. One reason some companies choose to parse html files as php is so that visitors cannot discover that php is actually being used on the site.

If you have only a few files, I would definitely recommend you just rename them to .php. Then you can run them on any server. If you really want to keep the html extension on files with php source, you will have to use a server with a custom setup. Using .htaccess is one way to achieve it, but I think there are more direct parameters you can set in Apache, such as "if filetype = html, process as php". Don't take that pseudo-code very seriously.

I'm sure some people here use the mod-rewrite feature of .htaccess, and a few of them may know the Apache file type settings. You probably cannot change the Apache file type settings at Frihost, however.
rvec
I think you can use the settings used in the link georgeodowd posted. But that would make the server interpret all html files as if they were php. The other way it to use mod_rewrite, that would also use htaccess, and you'd rename the files. The advantage of mod_rewrite is that a user still sees it as if it is a html file, but the server sees a php file.
georgeodowd
Thanks guys. I've decided to just go ahead and make .php files for my personal site. It certainly seems like the more sensible approach in my case, since my attempts to modify .htaccess didn't work, and I don't want to slow down the processing on straight html pages.
Related topics
PHP or HTML
[PHP] HTML entities, inputs, quotes
php/HTML pages question
SSI within php coded files
php dil çevirmede yardým edin lütfen
How to upload a file via html-form and php?
How to change extension php to html but the php script still
How to Set up Local Web Server
php html tags
Make me a job application page in php and earn 110 FRIH$!
Making a Dynamic link button
SOLVED::PHP upload_max_filesize
javascript php html styling and good practice.
Embed PHP+HTML
Reply to topic    Frihost Forum Index -> Support and Web Hosting -> Web Hosting Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.