php shows code [Solved]

Problems with the Windows version of XAMPP, questions, comments, and anything related.

php shows code [Solved]

Postby Esthermiller » 28. May 2012 07:53

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.
Esthermiller
 
Posts: 3
Joined: 28. May 2012 07:23
XAMPP Version: 1.8.3
Operating System: Windows 7

Re: php shows code

Postby Altrea » 28. May 2012 08:32

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
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6844
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: Windows 10 Pro x64

Re: php shows code

Postby Esthermiller » 28. May 2012 08:40

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
Esthermiller
 
Posts: 3
Joined: 28. May 2012 07:23
XAMPP Version: 1.8.3
Operating System: Windows 7

Re: php shows code

Postby Altrea » 28. May 2012 08:51

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
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6844
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: Windows 10 Pro x64

Re: php shows code

Postby Esthermiller » 28. May 2012 09:18

You have finished my suffering. Thanks. I didn't realize I needed to call it through the localhost.

Very appreciated.

Esther.
Esthermiller
 
Posts: 3
Joined: 28. May 2012 07:23
XAMPP Version: 1.8.3
Operating System: Windows 7

Re: php shows code

Postby Altrea » 28. May 2012 09:21

You are welcome.
Have fun with XAMPP and all that stuff 8)
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6844
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: Windows 10 Pro x64

Re: php shows code [Solved]

Postby minotti » 01. October 2012 21:32

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 :)
minotti
 
Posts: 1
Joined: 01. October 2012 21:18
XAMPP Version: 5.6.3
Operating System: Windows 7

Re: php shows code [Solved]

Postby danielcenoz » 20. January 2014 00:41

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
danielcenoz
 
Posts: 1
Joined: 20. January 2014 00:36
XAMPP Version: 1.8.3-3
Operating System: Windows 8

Re: php shows code [Solved]

Postby Altrea » 20. January 2014 00:52

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
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6844
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: Windows 10 Pro x64

Re: php shows code [Solved]

Postby kawal » 04. September 2014 23:27

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
kawal
 
Posts: 1
Joined: 04. September 2014 23:23
XAMPP Version: 5.6.3
Operating System: 8.1

Re: php shows code [Solved]

Postby Altrea » 05. September 2014 06:31

You are very welcome :D
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6844
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: Windows 10 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 63 guests