Page 1 of 1

Hello World Not working......seriously.....

PostPosted: 16. November 2007 20:05
by highonlife
I am embarrassed to even say this, but i cannot get hello world to work , by embedding php in an html file.
Whats wierd is that i am able to get it to connect to a database, when i post to a .php file using an html form. But for some reason, the following code doesnt display anything.
I know im a newbie...someone please help....

<html>
<head>
</head>
<body>

<?php
echo 'hello world!';
?>
</body>
</html>

PostPosted: 16. November 2007 20:08
by highonlife
As a second point to the above...
When i try to view the page source, it shows me the php code.
I thought that when a file is parsed by apache, and it contains php code, it shouldnt do that.

PostPosted: 16. November 2007 20:50
by highonlife
Ok, i sort of figured it out, by looking at some other forums on the internet.

Basically you got to change the /apache/conf/extra/httpd-xampp.conf
and where it says
AddType application/x-httpd-php .php .php5 .php4 .php3 .phtml
just add
".html"

and it will also parse within html files.

Though i had a question, is there a specific reason why this was not allowed in the first place in the xampp default configuration?

PostPosted: 17. November 2007 00:29
by Izzy
This is not a "Basically you got to change" issue and there was no need to edit or change any .conf file.

php contained within html code is parsed by Apache if it knows it is php code, not just plain old html text - and has been pointed out in many previous posts in these forums - almost on a weekly basis (searching first by new users is always advised).

Any file that contains php code must have a file extension of .php not .html so the server knows to parse not only the html but also the php code.

This is standards behavior and works 100% of the time.

Open the xampp\apache\conf\mime.types and you will see that
MIME type
text/html html htm
Is just that - plain old text and the server knows what to do with it and will treat any php code just like any other text in the file.

Open (as you did) xampp\apache\conf\extra\httpd-xampp.conf and you will see that
MIME type
application/x-httpd-php .php .php5 .php4 .php3 .phtml
Is just that a php application that needs parsing by Apache and the server knows just how to handle the php code and any html that it finds in the file.

Of course, you can do what you did by your choice, but if you had followed standard procedure and named your file, that included php code that needed parsing, with the correct file extension then, as by design, XAMPP will work "right out of the box".


===========================================
1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================

PostPosted: 17. November 2007 15:04
by LooseCannon
Why would one want to embed php within an html page, as highonlife has done? I not trying to be funny or make fun, just check if I've missed something.

One embeds hmtl within php to make it server side. The other way around throws the php code right at the client. Yes, no, have another coffee LC?!?

PostPosted: 17. November 2007 16:46
by highonlife
Loose Cannon,

By embedding PHP into an html page, i can make forms work better. And you can have dynamic content in an html page.
I didnt know that XAMPP needed all its files named php or phtml. Personally, i would have preferred havhing the ability to put php in html files out of the box.

PostPosted: 19. November 2007 05:01
by Izzy
highonsomthing wrote:By embedding PHP into an html page, i can make forms work better.
How?

Your statements and comments remind me of someone who lives in a country where everyone drives on the right hand side of the road because that is the rule of the road and also the standard, but for whatever reasons only known to that someone, chooses to drive on the left hand side of the road - and the consequences of which produce predictable results.


===========================================
1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================

PostPosted: 19. November 2007 14:39
by LooseCannon
Maybe worth getting to the bottom of this view point.... maybe not. ;)

highonlife wrote:By embedding PHP into an html page ... you can have dynamic content in an html page. ...
It's the PHP that give's dynamic content, not the html. Also, PHP works without the need to html.

highonlife wrote:I didnt know that XAMPP needed all its files named php or phtml.
It's not XAMPP that needs it, it's the way Apache has be created by the community, within existing MIME conventions. We already have html, so a new file suffix enables Apache to work its magic on the files it needs to know about.

Someone please correct or elucidate me, but if one has Apache/MySQL setup and available to you, then you no longer need use any html. PHP can do the static/boring stuff as well as dynamic wizardry.

Html ain't dynamic and it's visible to clients.

Maybe I'm missing your point highonlife. No worries. :)

Apologise to everyone for taking this thread off topic, but I thought I'd misunderstood the meaning of lifeImeanPHP. :P