Page 1 of 1

php code in .html file

PostPosted: 03. September 2006 15:02
by Etss
Hi!

I have some php code in a .html file...
The .html file is in the htdocs folder, but the browser does not recognize the php code...
I know I have to change the settings in apache/conf/httpd.conf file (or add something...), but I don't know how... :)

Can anyoane help me?
10x

PostPosted: 03. September 2006 17:33
by WorldDrknss
You need to add .html in xampp\apache\conf\extra\httpd-xampp.conf to AddType application/x-httpd-php

exampe:
AddType application/x-httpd-php .php .phtml .shtml .html

Save then restart apache.

PostPosted: 03. September 2006 21:37
by Etss
thanks.. it worked....
i'm using XAMPP for a few days only..
thanks again!

Re: php code in .html file

PostPosted: 04. September 2006 01:40
by Izzy
Etss wrote:Hi!

I have some php code in a .html file...
The .html file is in the htdocs folder, but the browser does not recognize the php code...
I know I have to change the settings in apache/conf/httpd.conf file (or add something...), but I don't know how... :)

Can anyoane help me?
10x

When you have mixed html and php in a single html or htm file and you don't have the confidence or the will to mess with .conf files then the simple solution is to rename the htmlplusphp.html or htmlplusphp.htm file to htmlplusphp.php. Apache will now render the html content and the php content. This method is simple and leaves your .conf files at their intended defaults.

So to recap, if you are creating mixed html and php files just save them with a .php extension instead of a .html or htm extension.

All Content Manager Scripts and most other web site scripts that I have come across that generate pages with mixed content do this by default, so you don't have to mess with the servers .conf files, which in a normal shared hosting environment, you would not have access to anyway.

Just to add on the above post, you would have to add the .htm extension if your files are named htmlplusphp.htm:
AddType application/x-httpd-php .php .phtml .shtml .html .htm

Nützt bei mir alles nichts ...

PostPosted: 07. September 2006 09:57
by bergsteiger
Irgendwie reicht das alles bei mir nicht aus. Ich habe .phtml-Dateien, die php-Code enthalten. Normalerweise sollten die funktionieren, da die entsprechenden Eintragungen ja auch standardmäßig in den Conf-Dateien drin sind. Aber trotzdem versucht der Browser die .phtml-Dateien runterzuladen. Ich weiß, dass ich auch php-Dateien machen könnte (die funzen im Übrigen auch!) aber es muss doch dafür eine Lösung geben.
Gibts da was, das ich übersehen haben könnte?

Sicher sitzt der Fehler allerdings vor dem Bildschirm :(

Re: Nützt bei mir alles nichts ...

PostPosted: 07. September 2006 10:04
by Izzy
bergsteiger wrote:Irgendwie reicht das alles bei mir nicht aus. Ich habe .phtml-Dateien, die php-Code enthalten. Normalerweise sollten die funktionieren, da die entsprechenden Eintragungen ja auch standardmäßig in den Conf-Dateien drin sind. Aber trotzdem versucht der Browser die .phtml-Dateien runterzuladen. Ich weiß, dass ich auch php-Dateien machen könnte (die funzen im Übrigen auch!) aber es muss doch dafür eine Lösung geben.
Gibts da was, das ich übersehen haben könnte?

Sicher sitzt der Fehler allerdings vor dem Bildschirm :(

Dieses ist ein Englisches Forum. Bedeuteten Sie, auf Deutsch bekanntzugeben?

The file extension phtml seems to work just fine on my default 1.5.3a server.
To test I renamed xampp/index.php to index.phtml. It loaded just fine.

I had changed the httpd.conf file to reflect the new index.phtml in the DirectoryIndex directive.

After changing the links to the frames in the index.phtml like this:
<?php
if (file_get_contents("lang.tmp") == "") {
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
$uri = 'https://';
} else {
$uri = 'http://';
}
$uri .= $_SERVER['HTTP_HOST'];
header('Location: '.$uri.'/xampp/splash.php');
exit;
}

include "langsettings.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta name="author" content="Kai Oswald Seidler, Kay Vogelgesang, Carsten Wiedmann">
<link rel="icon" href="img/xampp.ico">
<title><?php echo $TEXT['global-xampp']; ?> <?php include '.version'; ?></title>
</head>

<frameset rows="68,*" border="0" framespacing="0">
<frame name="head" src="head.phtml" frameborder="0" scrolling="no">
<frameset cols="175,*" border="0" framespacing="0">
<frame name="navi" src="navi.phtml" frameborder="0" scrolling="auto">
<frame name="content" src="start.phtml" frameborder="0" marginwidth="20">
</frameset>
</frameset>
</html>

the XAMPP Welcome Page complete wih all the frames .phtml files loaded perfectly.

So I don't see an issue with naming mixed php and html content to .phtml.

Neither do I see an issues with naming mixed php and html to .php.

If you have an issue with mixed php and html with a .html extension or you have a pure php file and you name it with a .html extension (apache will not render pure php in a .html extension file) then a rename or an httpd-xampp.conf edit is inevitable.

Sorry and THX

PostPosted: 07. September 2006 13:45
by bergsteiger
Sorry for the posting in German. It won't happen again.
I sad it: The error is sitting in front of the monitor ...
I make the same as you with the xampp/index.php and it works! So it seems the error is in my .htaccess-File. I renamed it and my site is loaded.

Thanks for your help.