PHP-Yes, HTML-No --- Why?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lennart Björk

    PHP-Yes, HTML-No --- Why?

    Hi All,

    I have a tiny program:

    <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>MyTitl e</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1"/>
    </head>
    <body>

    <?php
    $host = $_SERVER['HTTP_HOST'];
    $server = strtolower($hos t);

    echo 'My variables<bg>';

    echo("<br>Host: $host");
    echo("<br>Serve r: $server");

    ?>
    </body>
    </html>

    I upload it to my webserver as test.html and as test.php. Then I test
    them in my webbrowser. The test.html does not work, but the test.php
    does. Can someone tell me why?

    Very confused
    Lennart Björk
  • Barry

    #2
    Re: PHP-Yes, HTML-No --- Why?

    Lennart Björk wrote:[color=blue]
    > Hi All,
    >
    > I have a tiny program:
    >
    > <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    > "http://www.w3.org/TR/html4/strict.dtd">
    > <html>
    > <head>
    > <title>MyTitl e</title>
    > <meta http-equiv="Content-Type" content="text/html;
    > charset=iso-8859-1"/>
    > </head>
    > <body>
    >
    > <?php
    > $host = $_SERVER['HTTP_HOST'];
    > $server = strtolower($hos t);
    >
    > echo 'My variables<bg>';
    >
    > echo("<br>Host: $host");
    > echo("<br>Serve r: $server");
    >
    > ?>
    > </body>
    > </html>
    >
    > I upload it to my webserver as test.html and as test.php. Then I test
    > them in my webbrowser. The test.html does not work, but the test.php
    > does. Can someone tell me why?[/color]

    Because only .php files get interpreted.
    (Well assuming you've got a standard web server configuration)

    test.html just gets printed out right?

    Regards,
    Barry
    [color=blue]
    >
    > Very confused
    > Lennart Björk[/color]

    Comment

    • Lennart Björk

      #3
      Re: PHP-Yes, HTML-No --- Why?

      Barry,
      [color=blue]
      > test.html just gets printed out right?[/color]

      To a certain extent, yes. It looks like
      [color=blue][color=green][color=darkred]
      >>>[/color][/color][/color]
      '; echo("
      Host: $host"); echo("
      Server: $server"); ?>
      <<<

      I am still confused.

      Lennart Björk

      Comment

      • Barry

        #4
        Re: PHP-Yes, HTML-No --- Why?

        Lennart Björk wrote:[color=blue]
        > Barry,
        >[color=green]
        > > test.html just gets printed out right?[/color]
        >
        > To a certain extent, yes. It looks like
        >[color=green][color=darkred]
        > >>>[/color][/color]
        > '; echo("
        > Host: $host"); echo("
        > Server: $server"); ?>
        > <<<
        >
        > I am still confused.
        >[/color]

        ok
        the way php works is that if the web server
        has to serve a file with a .php extension, it
        recognises it as a PHP file and it sends it through the
        PHP parser and then it serves you the resulting html.

        the .html file just gets served as is.

        because .php went though the parser, you get the parsed php results
        because .html just got served, you got the php code as is

        it is possible to set up the server to send .html files through
        the parser aswell, but as a norm this is not done.

        Regards,
        Barry
        [color=blue]
        > Lennart Björk[/color]

        Comment

        • Lennart Björk

          #5
          Re: PHP-Yes, HTML-No --- Why?

          Barry,

          I do thank you for your help. But[color=blue]
          >[/color]
          it is possible to set up the server to send .html files through
          the parser aswell, but as a norm this is not done.
          <
          sounds a bit strange. Shouldn't I be able to put pieces of PHP-code in
          HTML-code of HTML-files. I think I have done it many times and it has
          worked without any special arrangements with the webserver.

          Lennart Björk

          Comment

          • d

            #6
            Re: PHP-Yes, HTML-No --- Why?

            "Lennart Björk" <lennart.bjork@ bibserv.com> wrote in message
            news:C9JBf.1545 94$dP1.513001@n ewsc.telia.net. ..[color=blue]
            > Barry,
            >
            > I do thank you for your help. But[color=green]
            > >[/color]
            > it is possible to set up the server to send .html files through
            > the parser aswell, but as a norm this is not done.
            > <
            > sounds a bit strange. Shouldn't I be able to put pieces of PHP-code in
            > HTML-code of HTML-files. I think I have done it many times and it has
            > worked without any special arrangements with the webserver.[/color]

            This is by no means the norm, but it's definitely how I prefer to work (as
            it looks a lot neater than having your dirty laundry aired for all to see).
            That is unless I'm using a site engine, in which case it doesn't matter :)
            [color=blue]
            > Lennart Björk[/color]

            dave


            Comment

            • Barry

              #7
              Re: PHP-Yes, HTML-No --- Why?

              Lennart Björk wrote:[color=blue]
              > Barry,
              >
              > I do thank you for your help. But[color=green]
              > >[/color]
              > it is possible to set up the server to send .html files through
              > the parser aswell, but as a norm this is not done.
              > <
              > sounds a bit strange. Shouldn't I be able to put pieces of PHP-code in
              > HTML-code of HTML-files. I think I have done it many times and it has
              > worked without any special arrangements with the webserver.
              >[/color]

              yes, you could put php code into html code of html files but it should
              have a .php extension.
              else, maybe your web server was setup differently without you knowing
              about it.

              cheers
              Barry
              [color=blue]
              > Lennart Björk[/color]

              Comment

              • Lennart Björk

                #8
                Re: PHP-Yes, HTML-No --- Why?

                Dave,
                [color=blue]
                > dirty laundry aired for all to see[/color]

                Do you mean that PHP-code in files with php as filename extension cannot
                be seen as 'view source'?

                Lennart Björk

                Comment

                • Lennart Björk

                  #9
                  Re: PHP-Yes, HTML-No --- Why?

                  Barry,
                  [color=blue]
                  >[/color]
                  maybe your web server was setup differently without you knowing about it
                  <
                  May well be. Somehow I have to adapt my code and my file names to the
                  common norm for webservers. So my conclusion is that PHP-code should
                  preferably be in files with php as file name extention?

                  Lennart Björk

                  Comment

                  • Barry

                    #10
                    Re: PHP-Yes, HTML-No --- Why?

                    Lennart Björk wrote:[color=blue]
                    > Barry,
                    >[color=green]
                    > >[/color]
                    > maybe your web server was setup differently without you knowing about it
                    > <
                    > May well be. Somehow I have to adapt my code and my file names to the
                    > common norm for webservers. So my conclusion is that PHP-code should
                    > preferably be in files with php as file name extention?
                    >[/color]
                    yes, I guess that would be better.
                    and yes, once parsed, you cannot see the PHP code in view source.

                    cheers
                    Barry[color=blue]
                    > Lennart Björk[/color]

                    Comment

                    • d

                      #11
                      Re: PHP-Yes, HTML-No --- Why?

                      "Lennart Björk" <lennart.bjork@ bibserv.com> wrote in message
                      news:ONJBf.4324 4$d5.199425@new sb.telia.net...[color=blue]
                      > Dave,
                      >[color=green]
                      > > dirty laundry aired for all to see[/color]
                      >
                      > Do you mean that PHP-code in files with php as filename extension cannot
                      > be seen as 'view source'?
                      >
                      > Lennart Björk[/color]

                      I mean as in you are showing the world what technology you're using :) The
                      pages are spitting out HTML, and so logically should have a .html extension
                      when the browser sees them (as the extension signifies the contents of the
                      file, even though web browsers shouldn't use that to determine the contents
                      of the file, people still do).

                      View source (.phps) should never be enabled, as it's so ridiculously
                      dangerous it's not even funny :)


                      Comment

                      • d

                        #12
                        Re: PHP-Yes, HTML-No --- Why?

                        "Lennart Björk" <lennart.bjork@ bibserv.com> wrote in message
                        news:ETJBf.4324 5$d5.199307@new sb.telia.net...[color=blue]
                        > Barry,
                        >[color=green]
                        > >[/color]
                        > maybe your web server was setup differently without you knowing about it
                        > <
                        > May well be. Somehow I have to adapt my code and my file names to the
                        > common norm for webservers. So my conclusion is that PHP-code should
                        > preferably be in files with php as file name extention?[/color]

                        That's how most web servers work, but it can be changed with a very slight
                        modification to your httpd.conf (if you're using apache), or IIS setup
                        graphical wizard thingy. Personally, I prefer html being parsed through
                        PHP. The performance hit is absolutely minimal on a system using PHP as a
                        module (on CGI setups, it requires a PHP process be spawned to handle it,
                        which can be a problem on highly-trafficked sites).
                        [color=blue]
                        > Lennart Björk[/color]


                        Comment

                        • Geoff Berrow

                          #13
                          Re: PHP-Yes, HTML-No --- Why?

                          Message-ID: <w%JBf.8876$wl. 1464@text.news. blueyonder.co.u k> from d
                          contained the following:
                          [color=blue]
                          >I mean as in you are showing the world what technology you're using :)[/color]

                          Smiley noted but it doesn't seem to bother people using other
                          technologies, why does it seem to bother people who use PHP?

                          Open source stigma? Yeah, that's it. PHP is free so it can't be any
                          good, people who use it are just amateurs, yadda, yadda...

                          I think the only way to overcome that is for more people to use the .php
                          extension, not less.

                          --
                          Geoff Berrow (put thecat out to email)
                          It's only Usenet, no one dies.
                          My opinions, not the committee's, mine.
                          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                          Comment

                          • d

                            #14
                            Re: PHP-Yes, HTML-No --- Why?

                            "Geoff Berrow" <blthecat@ckdog .co.uk> wrote in message
                            news:86kft116nj 3huqeke2lshv3fr j20enk1kg@4ax.c om...[color=blue]
                            > Message-ID: <w%JBf.8876$wl. 1464@text.news. blueyonder.co.u k> from d
                            > contained the following:
                            >[color=green]
                            >>I mean as in you are showing the world what technology you're using :)[/color]
                            >
                            > Smiley noted but it doesn't seem to bother people using other
                            > technologies, why does it seem to bother people who use PHP?[/color]

                            If I were to develop in ASP, I would have .html as well. The reason we
                            don't use .html is simply because that's how web servers determine which
                            pages need parsing. I don't like that, as the files, when downloaded, are
                            straight HTML. Having to change the clean nature of HTML files because of
                            perceived limitations in technology is not nice, in my eyes. That's why I
                            want my files that contain HTML to be called .html when the user gets them
                            :)
                            [color=blue]
                            > Open source stigma? Yeah, that's it. PHP is free so it can't be any
                            > good, people who use it are just amateurs, yadda, yadda...[/color]

                            That's not it at all - I see no stigma at all about open source :) As a
                            professional open-source developer, that would be a rather career-limiting
                            move ;)
                            [color=blue]
                            > I think the only way to overcome that is for more people to use the .php
                            > extension, not less.[/color]

                            I don't think there is a stigma, at least not amongst people people who know
                            what they're doing :)
                            [color=blue]
                            > --
                            > Geoff Berrow (put thecat out to email)
                            > It's only Usenet, no one dies.
                            > My opinions, not the committee's, mine.
                            > Simple RFDs http://www.ckdog.co.uk/rfdmaker/[/color]


                            Comment

                            • Andrew DeFaria

                              #15
                              Re: PHP-Yes, HTML-No --- Why?

                              d wrote:[color=blue]
                              > I mean as in you are showing the world what technology you're using :)[/color]
                              Who the hell cares? I mean aside from you![color=blue]
                              > The pages are spitting out HTML, and so logically should have a .html
                              > extension when the browser sees them[/color]
                              Hmmmm... That logic doesn't even make sense. You can have a Perl script
                              or a .exe file that "spits out" just text. Should such files have a .txt
                              extension?!? The .html signifies that the file contains HTML - and
                              pretty much only HTML. A php script contains both HTML and PHP code so
                              technically speaking it's not just HTML.[color=blue]
                              > (as the extension signifies the contents of the file, even though web
                              > browsers shouldn't use that to determine the contents of the file,
                              > people still do).[/color]
                              Why do you think that browsers shouldn't determine the contents of the
                              file from it's extension? Truth is it does, multiple times over in many,
                              many different occasions. Ever hear of mime.types? Ever actually
                              configure an Apache server?

                              And what's so wrong about doing that anyway? Until and unless we have a
                              robust and reliable object oriented and typed file system extensions
                              will be the way to go.
                              --
                              For my birthday I got a humidifier and a de-humidifier...I put them in
                              the same room and let them fight it out...

                              Comment

                              Working...