Forum Moderators: coopster

Message Too Old, No Replies

php statements in html not getting parsed

How can I to properly include php-statements in html-code?

         

benni_203

3:34 pm on Mar 6, 2005 (gmt 0)

10+ Year Member



Hello,

I am a newbie to php and if this question is too stupid or if this is the wrong place to ask this kind questions ... please forgive ;-) But I am desperate and don't find anything nowhere.

Here is today's challenge: I want to write a simple html-page to get the first step in starting with php:

<html>
<body>

<?php echo "Hello World";?>

</body>
</html>

... when save it as "test.html", ftp it to my webhoster and open it via a browser, it is not giving any output.

First I thought that it would be the webhoster not having php active, but php is included in my hosting package and any .php script is working (they have the infophp.php in my main directory and I recently added a mail.php and both work properly). I have a second hoster for another project ... exactly the same situation: any .php is working, any <? php > in html is not :-(

What the heck am I doing wrong? I am at the end of my rope with getting that simple statement working. Maybe I have to add something in the header and tell the browser where to look for the server php installation?

Any help is highly appreciated!
Thanks
Benni

Voltec

4:34 pm on Mar 6, 2005 (gmt 0)

10+ Year Member



You have to either save the file with a .php extension, or add/modify your .htaccess in the directory.

I modified my .htaccess so the files will be 'more SE friendly' by adding the following:

<Files *.html> 
forcetype application/x-httpd-php
</Files>

DefaultType application/x-httpd-php

Don't know if that is the best way of doing it or not but it is working for me... ;)

Hope it helps,
Matt

ergophobe

4:46 pm on Mar 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is the right place for that question and all questions and all persons are welcome here, regardless of how little or how much they know about PHP.

As Voltec said, somehow or other, you have to tell the server which files to treat as PHP. By default, this is usually only files that end in .php so you need to either name your files accordingly or adjust your server settings as Voltec suggested. Either method should work. If you don't have the right to make server settings in .htaccess files, then you'll need to just name the files .php

[edited by: ergophobe at 5:06 pm (utc) on Mar. 6, 2005]

benni_203

4:56 pm on Mar 6, 2005 (gmt 0)

10+ Year Member



@Voltec and @ergophobe

thank you sooo much! I knew I missed something stupid.

I adjusted the .htaccess-file as you wrote and it works just perfect now. I do prefer .html endings over .php, so that tip is great!

Have a fantastic day!
Benni

jlryan

8:02 pm on Mar 6, 2005 (gmt 0)

10+ Year Member



Matt, can you please tell me where I would go to add/modify my .htaccess in the directory? I understand how, but don't understand where to do it.

Thanks,

Jennifer

benni_203

8:38 pm on Mar 6, 2005 (gmt 0)

10+ Year Member



the .htaccess file is not visible, even if one would be there. You have to create a new one in a text editor, save it under the file name ".htaccess" and then move it to the root of your webspace. Just copy the text like it is in it.

<Files *.html>
forcetype application/x-httpd-php
</Files>

The only thing I am not sure is how to avoid overwriting anything which is already in there ... but most of the times there is nothing in there anyways.

Voltec

10:36 am on Mar 7, 2005 (gmt 0)

10+ Year Member



I use CuteFTP and it is visible via a directory listing there. I am guessing that if you get a directory listing via FTP and it isn't listed, there probably isn't one there and it is safe to add one.

If there is one there, be sure to download it first and then edit it. Some of my control panel settings modify mine, so I always download it first.

Have fun,
Matt