Why am I seeing the PHP code in the browser?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sirab33
    New Member
    • Aug 2009
    • 10

    #16
    UPDATE: when I put this into my browser



    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?

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #17
      Originally posted by sirab33
      I'm assuming this is a GOOD thing, yes?
      definitely

      Originally posted by sirab33
      In FIREFOX, its even worse: when I open a .PHP file Firefox gives me this … Its like it won't even consider opening it in the browser.

      Does this give us any clues as to what's going on?
      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)

      Comment

      • sirab33
        New Member
        • Aug 2009
        • 10

        #18
        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!

        Comment

        • dlite922
          Recognized Expert Top Contributor
          • Dec 2007
          • 1586

          #19
          uh.....yeaaaaaa a

          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

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #20
            Originally posted by sirab33
            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.
            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

            Comment

            • sirab33
              New Member
              • Aug 2009
              • 10

              #21
              Originally posted by Dormilich
              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
              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 "recommende d" 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

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #22
                Originally posted by sirab33
                Its kinda of a big DUH on everyone's part :-)
                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).

                Comment

                • sirab33
                  New Member
                  • Aug 2009
                  • 10

                  #23
                  no problem - i'm sure I'll be back - with even sillier more obvious questions! ;-)

                  Comment

                  • Danzamagu
                    New Member
                    • Sep 2009
                    • 1

                    #24
                    Maybe?

                    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/~yourcomputerus ername/thedirectory/yourphpfile.php

                    Comment

                    Working...