472,378 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

Why am I seeing the PHP code in the browser?

10
Hi All,

Actionscript/Javascript programmer new to PHP.
Just installed MAMP on my MacBook - no problems, all works well.
Also successfully configured Dreamweaver to work with Apache/MySql (using official Adobe instructions)- again, no problems.

I'm now trying to run some very basic PHP pages - intro/tutorials type stuff - but they don't work: content generated with regular HTML shows up correctly but anything in <?php> tags does not show up at all.

Also, pages that are exclusively in PHP show up as literal code on the browser. Its as if I was looking at them in a regular text-editor.

Obviously there's some issues having to do with PHP being incorrectly interpreted - any ideas on how to fix this?
Aug 10 '09 #1
23 14261
Markus
6,050 Expert 4TB
Your server isn't parsing them as PHP. Sure you've got the server running? Files using correct extension (.php)? How about your error logs (apache) - anything in them?

Mark.
Aug 10 '09 #2
Dormilich
8,658 Expert Mod 8TB
some more

- did you stop the native Apache on Mac
- using short tags when disabled (though you mentioned <?php ?>)
- PHP module not loaded
- php extention not registered in Apache
Aug 10 '09 #3
sirab33
10
Gentlemen,

In response to your questions, here's what I know:
-the MAMP app has the green lights ON for both Apache and MySQL Servers which I take it means they're both running correctly
-I am indeed using the correct .php extension in my file-names
-re Apache error-logs - how do you access these?
-re "did you stop native Apache on Mac?" - I don't know that I already had it running. I believe it comes with OS 10.5 but I'm on 10.4.11 so I don't think I ever had it pre-installed - but is this correct? How can I find out?
-Not using short-tags - at least I don't think that I am. I know I didn't enable them anywhere...I basically copy-pasted some very basic PHP code from online tutorials so I'm pretty sure the code is right.
-No idea if the PHP module is loaded or not - how do I check for this?
-Same thing for PHP extensions registered in Apache - how do I check for this?

thanks :-)
Aug 10 '09 #4
Markus
6,050 Expert 4TB
Try at the command line apache2 -M, or httpd -M, not sure which it is on Mac.
Aug 10 '09 #5
sirab33
10
@Markus
ok, I'm sorry but I don't what "the command line" is - how/where do you access it?

Note that I'm a straight coder, I don't have any experience with system-admin/server/OS type stuff - but I'm generally pretty bright and can follow directions very well if they're clear :-)
So, where do I go to get this command line?
Aug 10 '09 #6
Markus
6,050 Expert 4TB
@sirab33
My bad - it's possibly called the 'terminal' in Mac. Not all that sure how you open it on a Mac, but google will be able to help you there.

Mark.
Aug 10 '09 #7
Dormilich
8,658 Expert Mod 8TB
@sirab33
the Command Line (alias CLI) is your access through the base system (Darwin), the most powerful tool on any Posix machine.

to be found via Applications > Utilities > Terminal.app


thereís an Apache even in OS 10.4 (though it is Apache 1.3, I believe), access via Applications > (System) Preferences > Sharing >> Web Sharing

if you have the native Apache running, MAMP might not be accessed (because another programme is already listening on port 80)


well, if you upgrade to 10.5 you get Apache 2 and PHP 5 built-in (thereís no built-in PHP in 10.4 but there are PHP packages to install)

Apache conf / log should be something around
/etc/var/log/apache/error_log
/etc/apache/httpd.conf
- thereís somewhere a section about loaded modules (use search option, the conf file is quite long)
Aug 10 '09 #8
sirab33
10
@Dormilich
OK, so if it is the case that I had an earlier version of Apache on my OS 10.4, what should I do now? Can I disable it without disabling the new one? Or do I unistall the new one and the old one and start a new MAMP installation from scratch?
And if so, how? Is there an un-install for MAMP?

In terms of accessing Apache, I opened Application-->(System) Preferences-->Sharing - but there's nothing called "Web Sharing". There's something called "Personal Web Sharing" - which is currently not selected/checked on - is that the same thing? (Its under the "Services" tab. There are also "Firewall" and "Internet" tabs.)
Aug 10 '09 #9
Dormilich
8,658 Expert Mod 8TB
@sirab33
stick with MAMP (especially with 10.4)*

@sirab33
MAMP deinstallation** is described on their web site (delete the MAMP folder)

@sirab33
I was guessing from 10.5. so youíre at the right place. and if itís not checked, itís disabled (so you also donít need to worry about logsÖ)

then youíll have to check MAMPís documentation to find where you have to look for the config / logs (I only use MacPorts)

* you might also look at MacPorts
** deinstallation on Mac is simpleójust delete it
Aug 10 '09 #10
sirab33
10
I found this when I opened the php_error.log file - it says the following:
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 83
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 86
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 89
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 92
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 95
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 98
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 83
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 86
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 89
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 92
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 95
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 98

so that help make sense of whatever's wrong?
Aug 10 '09 #11
dlite922
1,584 Expert 1GB
it's just a notice, but you should always initialize your variables before using them.

Your error says:
1. A variable was used without being initialized.
2. It's called 'localtheme".
3. It's in /defined.inc.php
4. It's on line number 95.


Dan
Aug 10 '09 #12
Dormilich
8,658 Expert Mod 8TB
doesnít look like itís related to being PHP not parsed. try finding the apache configuration file (httpd.conf)
Aug 10 '09 #13
sirab33
10
@dlite922
ok - but I don't know any of this code - I didn't write it - it came with this sample file - there's this whole how-to/tutorial on Adobe's site for configuring Dreamweaver to work with PHP - "Setting up a PHP development environment for Dreamweaver" - its really good actually - here:
http://www.adobe.com/devnet/dreamwea...ng_up_php.html

I followed it step-by-step and everything worked perfectly. Including a connection to MySQL - it all looked great.

I just can't get any PHP code to work and its beginning to drive me a little bonkers cause I followed every step exactly and every thing is supposedly fine: MAMP works, PHP is installed, I've got a Testing Server configured correctly, I've MySQL installed correctly, everything's done right - but PHP ain't working.

I'll ask again, and if someone can be a little clearer it would really help cause I can't make heads or tails out of some of these 1-line/half-phrase responses :-(
Ya'll need to remember I've got lots of programming experience but am totally new to this particular area of IT world and don't have the context or bgd. to understand some of the suggestions you've been making - and I hope I don't sound unappreciative, I just don't know what you guys are talking about :-)

1) Should I throw away the MAMP installation and start over?
2) If I start over, do I need to get rid of the the earlier version of Apache that came with OS 10.4? (I'm still on 10.4 - I'm not on 10.5)
3) If so, how do I do it?
4) Or, can I keep the earlier version of Apache but somehow disable it?
5) Is that even what's causing the problem?

Thinking about it logically, what are the possible things that can cause PHP to not work?
PHP is installed, it is loading - what gives?

Could it be some setting in the browser preferences?

What I don't get is why files that have both HTML and PHP in them ONLY display the HTML content and not the PHP content...

Any and all help would be greatly appreciated as I'm totally stuck on something that seems pretty simple...

Thank you much
-S
Aug 10 '09 #14
Dormilich
8,658 Expert Mod 8TB
@sirab33
1) if you donít find a solutionÖ maybe
2) no, itís already disabled/not running
3) I donít recommend messing with the OS
4) see 2)
5) I donít think so

@sirab33
well, a look at the Apache conf file should give you some answers

@sirab33
no, PHP is a server thing, although display may vary.

@sirab33
even in the source code?
Aug 11 '09 #15
sirab33
10
UPDATE: when I put this into my browser

http://127.0.0.1/phpinfo.php

I get this big long page full of tables with data and stats about PHP Version 5.2.6, Apache Environment, etc. etc.

I'm assuming this is a GOOD thing, yes?

Otherwise, I get very different results with SAFARI and FIREFOX when opening any file with a .php extension.
SAFARI keeps displaying the PHP code itself - what's weirder is that when I go to View>Source - its greyed out - not even available.

In FIREFOX, its even worse: when I open a .PHP file Firefox gives me this (roll-over this thumb-nail image):



Its like it won't even consider opening it in the browser.

Does this give us any clues as to what's going on?
Aug 11 '09 #16
Dormilich
8,658 Expert Mod 8TB
@sirab33
definitely

@sirab33
sure, this popup comes, if a document with an unknown mime type* is served (say e.g. text/php). Iíd say thereís something wrong within the Apache configuration file.

to get it working the mime type should be text/html (html) or application/xhtml+xml (xhtml)

* the browser 'knows' the mime types saved in the HTTP 1.1 Accept Header (you should find it in Firefoxí about:config)
Aug 11 '09 #17
sirab33
10
na that's not it.
the problem was that I didn't open the file from within the browser using http://127.0.0.1/filename

I was just opening them regularly, from within their folders, like regular HTML files.

You see, nobody told me that this is how you open PHP files - that you have to FORCE them to go through the Server, and that this is how its done.

Its kinda of a big DUH on everyone's part :-)

Everyone has been over-thinking this to death, coming up with weird exotic solutions - its a basic thing that should be told to all PHP newbies - but it wasn't in the READ ME files, I didn't see it in any tutorial files, FAQ's - nowhere. Its kind of a shame - it should be posted someplace :-)

anyway, thanks for the help!
Aug 11 '09 #18
dlite922
1,584 Expert 1GB
uh.....yeaaaaaaa

PHP is labeled as a server-side script. It is a big DUH. It's like saying you eat your salad with a fork, not a knife.

Many PHP install tutorials refer to Apache, a web server software.

We all miss obvious things like this, so it's ok. You'll eventually find the answer as you did.




Dan
Aug 11 '09 #19
Dormilich
8,658 Expert Mod 8TB
@sirab33
er, that's why you call it Server Side ScriptingÖ well, no way I could have thought of that.

besides that, it is mentioned how to use PHP: introduction, chapter 2
Aug 11 '09 #20
sirab33
10
@Dormilich
oh c'mon guys :-) saying "well PHP is Server Side Scripting" is a somewhat (highly!) general statement, don't you think? :-)

it certainly doesn't mean anything in the pragmatic sense, does it? :-)

Like if you're a newbie and you read the statement "PHP is a Server Side Scripting language" - does the first thing that pop into your head is "hmm, well then I better make sure I open my PHP files in the browser...like maybe using the Server path...and I bet the path to the Server is.... lets see...a series of numbers....like say...I dunno....1....2......maybe 7 - yeah that's it, 127....and then....how about a "." and then 0 and then...."

Know what I'm sayin'? :-)

I mean who in the world would think of that stuff? :-)

I dunno.
Perhaps it MAMP's "fault". They have this great download that installs EVERYTHING you need with one click - and it does work perfectly, but they never say anywhere "this is how you open PHP files" - but is it even their job to tell you that?

I dunno.

All I know is I started with this yesterday, downloaded MAMP, installed it, then started checking out some online tutorials - like at w3schools.com - great resource for everything - and they have all this great PHP sample code - so I started trying out stuff - like a simple "hello world" app - boom, didn't work, PHP code showing up IN the browser window, tried other code, tried it on other browsers - same problems.
And from there it was...down the rabbit hole... :-)

I looked through a zillion docs. - its crazy the amount of info that is "recommended" for you to look through....

hey man, life's too short to search, sift through and read a zillion docs. :-)

all good.

just wondering if there should be a "FOR PHP NEWBIES ONLY - MUST READ!!!" section somewhere in the PHP forums/tutorials sites, know what I'm sayin'?

I know as an experienced programmer - who also does a lot of training - its quite easy to forget that newbies don't know the first thing about stuff we take for granted.
I actually devised a cheat-sheet list of BASICS - I call it the "DUH SHEET"... :-)

Anyway, just my 2 cents - again, really appreciate the input and help - I'm just trying to improve things for the community - and for the next guy that falls down this rabbit-hole :-)

Thanks again, best of everything and CHEERS!
-S
Aug 11 '09 #21
Markus
6,050 Expert 4TB
@sirab33
On your part - don't lug me into this; you never said *how* you were opening your files... so it was safe for us to assume you were opening them via your server.

Also, to me at least, the phrase 'server-side' makes absolute sense: it is to be run through the server, but that is purely opinion.

Anyway - glad you've got it all working; and we our somewhat to-the-point/no-nonsense attitudes have not pushed you away from the forum - be sure to ask any questions you have!

Mark (gotta rush out).
Aug 11 '09 #22
sirab33
10
no problem - i'm sure I'll be back - with even sillier more obvious questions! ;-)
Aug 11 '09 #23
Sirab, I had no time to read ALL the comments in this post, so I do not know if this was already suggested to you or not, or if you are doing this..

One common error with running PHP files in a local machine is that people open the file incorrectly in the browser.

try this:

http://localhost/~yourcomputerusername/thedirectory/yourphpfile.php
Sep 18 '09 #24

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Alan Mackenzie | last post by:
I've recently moved onto a C++ project with a large number of directories (several hundred) containing an even larger number of C++ source files. There are vastly more ways in C++ to obfuscate a...
1
by: Vinay | last post by:
Hi Everybody, I have been using a combination of ctags, cscope & vi editor as a code browsing tool for my millions of lines of C/C++ code. Each of my development environment, need not...
3
by: Stefan Schwarzer | last post by:
Hello, from time to time I want to inspect the source code of projects on remote computers.(*) I've googled for one or two hours but didn't find anything helpful. :-/ I'm looking for something...
27
by: David Golightly | last post by:
This is just a quick poll for all you web devs out there: What browsers do you test on/are concerned about compatibility with? Obviously, you're going to test on current-generation browsers such...
4
by: ken | last post by:
We are looking for C# developers who use Visual Studio 2005 to help test our new code browser, CodeSkipper. Briefly, CodeSkipper is a code browser, implemented as a toolwindow addin to Visual...
3
by: Rahul | last post by:
hi, which is the best source code browser for c / c++ source code... on windows.. better if its free download... i tried source navigator 5.1.4 and 5.2b2.. but it is crashing while parsing the...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.