Page 1 of 1

php shows code [Solved]

PostPosted: 28. May 2012 07:53
by Esthermiller
I'm studying PHP. I want to try the code as I go. I've installed XAMPP 1.7.4 and it worked fine. Now the problem I've got is that PHP doesn't give me a result but the code. I've been dealing with this problem for a few days. I have realized that it works (shows results) until I try code with errors, then the simple
<?php
echo 'Hello world';
?>
fails.
Looking in forums I found that I need to add:
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php .php5 .php4 .php3 .phtml .php
to httpd.conf.
In this forums adviced that I should add:
LoadModule php5_module "d:/xampp/php/php5apache2.dll"
to httpd.conf as well. When I've done it APACHE fails, so I commented it out in httpd.conf.

I'm desparate because I want to study no spend my time fixing the tool. Help, please.

Re: php shows code

PostPosted: 28. May 2012 08:32
by Altrea
Hi Esthermiller (there is ALWAYS time for an introducing welcome line, especially if you want to ask for help. It's a matter of politeness),

Esthermiller wrote:Looking in forums I found that I need to add:
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php .php5 .php4 .php3 .phtml .php
to httpd.conf.
In this forums adviced that I should add:
LoadModule php5_module "d:/xampp/php/php5apache2.dll"
to httpd.conf as well.

All of this changes are unnecessary. XAMPP is already well configured out of the box to work with PHP files.

What does your browser address bar show you at the time you only get the plain php code?

best wishes,
Altrea

Re: php shows code

PostPosted: 28. May 2012 08:40
by Esthermiller
Hi Altrea,
You are very right, I was rude, no excuses.
Thanks for your prompt replay.
My browser bar shows:
D:\xampp\htdocs\Esther\hola.php

Cheers,

Esther

Re: php shows code

PostPosted: 28. May 2012 08:51
by Altrea
Esthermiller wrote:My browser bar shows:
D:\xampp\htdocs\Esther\hola.php

And thats the problem.

serverside programming language files can't simply be opened in a program, they have to be processed, in your case by an php interpreter.
If you simply open the file in your browser, your browser simply doesn't know what to do with that file. Your browser analyzes the file, sees some HTML which he can render (he is really happy about that) and with the rest of the not understandable syntax he tries it's best to just output it as plain text.

Everything which results in an filebased path in your browsers address bar doesn't work. Webscript files has to be requested with a valid URL, like they are saved somewhere in the internet. For scripts saved on your own computer, the domainname localhost is mapped to your own computers loopback IP address 127.0.0.1. This domainname can be used in URLs.

Your Apache Webserver is listening on requests from a special port (by default port 80) and tries to find the file inside his allowed folder structure.
In your case D:\xampp\htdocs\ is by default the root folder for your Apache. This root folder can be requested very simple by requesting your local domainname http://localhost/
Every folder and file inside this root folder can be accessed by adding the name of it in the URL. For your example:
If you want to request your file D:\xampp\htdocs\Esther\hola.php The URL will be http://localhost/Esther/hola.php

best wishes,
Altrea

Re: php shows code

PostPosted: 28. May 2012 09:18
by Esthermiller
You have finished my suffering. Thanks. I didn't realize I needed to call it through the localhost.

Very appreciated.

Esther.

Re: php shows code

PostPosted: 28. May 2012 09:21
by Altrea
You are welcome.
Have fun with XAMPP and all that stuff 8)

Re: php shows code [Solved]

PostPosted: 01. October 2012 21:32
by minotti
Thanks Altrea.
I'm beginner in PHP and earlier I used EasyPhp for local server and few days ago I installed Xampp so I didn't know in which folder to save files and how to type line behind localhost. You help me much!
Thanks again :)

Re: php shows code [Solved]

PostPosted: 20. January 2014 00:41
by danielcenoz
Hi, Altrea!
I'm Daniel, from Brazil. I'm studyind PHP for my own (I'm a spanish teacher without previous program knowledge) and this problem was a lot of pain for me in the last days. A lot of headache for a little detail... but now, it works!
Thanks, thanks, thanks! :D :D :D

Re: php shows code [Solved]

PostPosted: 20. January 2014 00:52
by Altrea
Hi Daniel,

Greetings from Germany to Brazil :D
I'm glad that my post helped you out to solve your problem.
Have fun with XAMPP and all that stuff 8)

best wishes,
Altrea

Re: php shows code [Solved]

PostPosted: 04. September 2014 23:27
by kawal
thanks Altrea :D :D

m from india. and m beginner and cannot open the php program.. but after reading your suggestion m able to see my program..
thanks for your solution.. :D :D

Re: php shows code [Solved]

PostPosted: 05. September 2014 06:31
by Altrea
You are very welcome :D