Content in the head section??

Discussion in 'HTML' started by Tim W, Oct 12, 2013.

  1. Tim W

    Tim W Guest

    I have been looking through some free online php courses to learn a bit
    of basic php. Here is a sample page of one of them

    http://www.homeandlearn.co.uk/php/php4p6.html

    You will see the author puts a print() command in the head section of
    the html, to show effetively content on the html page. I was amazed it
    worked. I have never seen visible content in the head of an html document.

    I take it that this is completely bonkers and something which never
    ought to be done, or is there some reason to put stuff there sometimes?
    And why would a browser ever display any text from the head section?

    Tim W
     
    Tim W, Oct 12, 2013
    #1
    1. Advertising

  2. On 10/12/2013 06:02 AM, Tim W wrote:
    > I have been looking through some free online php courses to learn a bit
    > of basic php. Here is a sample page of one of them
    >
    > http://www.homeandlearn.co.uk/php/php4p6.html
    >
    > You will see the author puts a print() command in the head section of
    > the html, to show effetively content on the html page. I was amazed it
    > worked. I have never seen visible content in the head of an html document.
    >
    > I take it that this is completely bonkers and something which never
    > ought to be done, or is there some reason to put stuff there sometimes?
    > And why would a browser ever display any text from the head section?
    >
    > Tim W


    While it appears to work, it also appears to be a typo as in later
    pages the PHP is inside the <body> element, not the <head>. That being
    said, I am surprised that this also works (Google Chrome at least):

    <HTML>
    <HEAD>
    <TITLE>HEADer test</TITLE>
    <A ID=1 NAME=one HREF="blah">Header link</A><BR>
    </HEAD>
    <BODY>
    Body text
    </BODY>
    </HTML>

    I haven't investigated the validity of it nor can I think of a use
    either.


    --
    Norman
    Registered Linux user #461062
    AMD64X2 6400+ Ubuntu 10.04 64bit
     
    Norman Peelman, Oct 12, 2013
    #2
    1. Advertising

  3. 2013-10-12 13:17, Norman Peelman wrote:

    > I am surprised that this also works (Google Chrome at least):
    >
    > <HTML>
    > <HEAD>
    > <TITLE>HEADer test</TITLE>
    > <A ID=1 NAME=one HREF="blah">Header link</A><BR>
    > </HEAD>
    > <BODY>
    > Body text
    > </BODY>
    > </HTML>
    >
    > I haven't investigated the validity of it nor can I think of a use
    > either.


    It isn't valid of course. But it works, because the <A> element
    implicitly terminates the open <HEAD> element. You can see this if you
    inspect the page using the developer tools (F12): the Elements pane
    shows how the <A> is being treated as the first child of <BODY>.

    This doesn't have practical use. It just means that if you try to put
    visible content inside <HEAD>, it will succeed, since it will really be
    in the <BODY> element.

    In fact, division of <HTML> into <HEAD> and <BODY> is rather pointless.
    The division does not matter when the document is parsed and otherwise
    processed. And the *tags* <head>, </head>, <body>, and </body> are
    optional, except in XHTML, and even in real XHTML, they can be omitted
    in practice (if you omit both the opening tag and the matching closing
    tag), because it's just validity error (and browsers don't care about
    validity), not a well-formedness error.

    The division was probably introduced as "logical" in some people's
    logic, or as an attempt at trying to tell that <STYLE>, <LINK>, <META>
    etc. should appear at the start of a document rather than later. In
    practice, apart from special cases like <META> specifying charset, those
    tags can be scattered around - only HTML validators will care (and this
    might matter, since validators can spot significant errors, too).

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Oct 12, 2013
    #3
  4. On 10/12/2013 06:38 AM, Jukka K. Korpela wrote:
    > 2013-10-12 13:17, Norman Peelman wrote:
    >
    >> I am surprised that this also works (Google Chrome at least):
    >>
    >> <HTML>
    >> <HEAD>
    >> <TITLE>HEADer test</TITLE>
    >> <A ID=1 NAME=one HREF="blah">Header link</A><BR>
    >> </HEAD>
    >> <BODY>
    >> Body text
    >> </BODY>
    >> </HTML>
    >>
    >> I haven't investigated the validity of it nor can I think of a use
    >> either.

    >
    > It isn't valid of course. But it works, because the <A> element
    > implicitly terminates the open <HEAD> element. You can see this if you
    > inspect the page using the developer tools (F12): the Elements pane
    > shows how the <A> is being treated as the first child of <BODY>.
    >


    Ahh yes, I see that now. It's simply been moved the <BODY>.



    --
    Norman
    Registered Linux user #461062
    AMD64X2 6400+ Ubuntu 10.04 64bit
     
    Norman Peelman, Oct 12, 2013
    #4
  5. Tim W

    Tim W Guest

    On 12/10/2013 18:50, Norman Peelman wrote:
    > On 10/12/2013 06:38 AM, Jukka K. Korpela wrote:
    >> 2013-10-12 13:17, Norman Peelman wrote:
    >>
    >>> I am surprised that this also works (Google Chrome at least):
    >>>
    >>> <HTML>
    >>> <HEAD>
    >>> <TITLE>HEADer test</TITLE>
    >>> <A ID=1 NAME=one HREF="blah">Header link</A><BR>
    >>> </HEAD>
    >>> <BODY>
    >>> Body text
    >>> </BODY>
    >>> </HTML>
    >>>
    >>> I haven't investigated the validity of it nor can I think of a use
    >>> either.

    >>
    >> It isn't valid of course. But it works, because the <A> element
    >> implicitly terminates the open <HEAD> element. You can see this if you
    >> inspect the page using the developer tools (F12): the Elements pane
    >> shows how the <A> is being treated as the first child of <BODY>.
    >>

    >
    > Ahh yes, I see that now. It's simply been moved the <BODY>.
    >
    >
    >

    Although I can't see it has much to do with the <a> tag, even a bit of
    text without tags in the head displays on the page in the body

    Tim W
     
    Tim W, Oct 12, 2013
    #5
  6. 2013-10-12 23:40, Tim W wrote:

    > Although I can't see it has much to do with the <a> tag, even a bit of
    > text without tags in the head displays on the page in the body


    That's right. Any non-whitespace content also terminates the HEAD
    element and starts a BODY element. The HEAD element may *only* contain
    elements and whitespace.

    This doesn't matter much, except that validation will get confused, and
    this confuses the person trying to validate his pages. Oh, and it does
    affect the DOM. But the elements will be otherwise processed the same
    way, whether the browser things they are in the HEAD or in the BODY.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Oct 12, 2013
    #6
  7. Tim W

    Tim W Guest

    On 12/10/2013 21:52, Jukka K. Korpela wrote:
    > 2013-10-12 23:40, Tim W wrote:
    >
    >> Although I can't see it has much to do with the <a> tag, even a bit of
    >> text without tags in the head displays on the page in the body

    >
    > That's right. Any non-whitespace content also terminates the HEAD
    > element and starts a BODY element. The HEAD element may *only* contain
    > elements and whitespace.
    >
    > This doesn't matter much, except that validation will get confused, and
    > this confuses the person trying to validate his pages. Oh, and it does
    > affect the DOM. But the elements will be otherwise processed the same
    > way, whether the browser things they are in the HEAD or in the BODY.
    >


    Thanks. so it doesn't matter much in the context of that php tutorial
    except that it would be a very bizarre way of actually doing a real
    production page with a script on it.

    TW
     
    Tim W, Oct 12, 2013
    #7
  8. Tim W

    William Gill Guest

    On 10/12/2013 6:02 AM, Tim W wrote:
    > I have been looking through some free online php courses to learn a bit
    > of basic php. Here is a sample page of one of them
    >
    > http://www.homeandlearn.co.uk/php/php4p6.html
    >
    > You will see the author puts a print() command in the head section of
    > the html, to show effetively content on the html page. I was amazed it
    > worked. I have never seen visible content in the head of an html document.
    >
    > I take it that this is completely bonkers and something which never
    > ought to be done, or is there some reason to put stuff there sometimes?
    > And why would a browser ever display any text from the head section?
    >
    > Tim W


    Tim,

    Without going on the tangent about the invalid anchor tag in the head
    element, here is what's happening on the example given on the page you
    provided;

    Assume you have previously set $_POST['username'] to "Tim W":

    <html>
    <head>
    <title>A BASIC HTML FORM</title>
    <?PHP
    $username = $_POST['username'];
    print ($username);
    ?>
    </head>

    produces:

    <html>
    <head>
    <title>A BASIC HTML FORM</title>
    Tim W
    </head>

    examining the result, it is invalid.

    However if the code were changed to:

    <html>
    <head>
    <title>
    <?PHP
    $username = $_POST['username'];
    print ($username);
    ?>
    </title>
    </head>

    would produce:

    <html>
    <head>
    <title>Tim W</title>
    </head>

    which is valid.

    The inserted php snippets are run at the time the page is requested, and
    if the snippet produces text output, it will be placed at that point in
    the document, so if you tell php to type an invalid document it will.

    On the other hand if the example were changed to:
    <html>
    <head>
    <title>A BASIC HTML FORM</title>
    <?PHP
    $username = $_POST['username'];
    ?>
    </head>


    the snippet would not return any output so the result would be:

    <html>
    <head>
    <title>A BASIC HTML FORM</title>
    </head>

    but in the document the variable $username will contain whatever was in
    the "superglobal" array variable $_POST indexed as 'username'.

    All this means, you are right it is bonkers, and the example is flawed,
    but what it demonstrates is php will let you do things you don't really
    want to do if you are not careful.
     
    William Gill, Oct 16, 2013
    #8
  9. On 10/16/2013 02:33 PM, William Gill wrote:
    > On 10/12/2013 6:02 AM, Tim W wrote:
    >> I have been looking through some free online php courses to learn a bit
    >> of basic php. Here is a sample page of one of them
    >>
    >> http://www.homeandlearn.co.uk/php/php4p6.html
    >>
    >> You will see the author puts a print() command in the head section of
    >> the html, to show effetively content on the html page. I was amazed it
    >> worked. I have never seen visible content in the head of an html
    >> document.
    >>
    >> I take it that this is completely bonkers and something which never
    >> ought to be done, or is there some reason to put stuff there sometimes?
    >> And why would a browser ever display any text from the head section?
    >>
    >> Tim W

    >
    > Tim,
    >
    > Without going on the tangent about the invalid anchor tag in the head
    > element, here is what's happening on the example given on the page you
    > provided;
    >
    > Assume you have previously set $_POST['username'] to "Tim W":
    >
    > <html>
    > <head>
    > <title>A BASIC HTML FORM</title>
    > <?PHP
    > $username = $_POST['username'];
    > print ($username);
    > ?>
    > </head>
    >
    > produces:
    >
    > <html>
    > <head>
    > <title>A BASIC HTML FORM</title>
    > Tim W
    > </head>
    >
    > examining the result, it is invalid.
    >
    > However if the code were changed to:
    >
    > <html>
    > <head>
    > <title>
    > <?PHP
    > $username = $_POST['username'];
    > print ($username);
    > ?>
    > </title>
    > </head>
    >
    > would produce:
    >
    > <html>
    > <head>
    > <title>Tim W</title>
    > </head>
    >
    > which is valid.
    >
    > The inserted php snippets are run at the time the page is requested, and
    > if the snippet produces text output, it will be placed at that point in
    > the document, so if you tell php to type an invalid document it will.
    >
    > On the other hand if the example were changed to:
    > <html>
    > <head>
    > <title>A BASIC HTML FORM</title>
    > <?PHP
    > $username = $_POST['username'];
    > ?>
    > </head>
    >
    >
    > the snippet would not return any output so the result would be:
    >
    > <html>
    > <head>
    > <title>A BASIC HTML FORM</title>
    > </head>
    >
    > but in the document the variable $username will contain whatever was in
    > the "superglobal" array variable $_POST indexed as 'username'.
    >
    > All this means, you are right it is bonkers, and the example is flawed,
    > but what it demonstrates is php will let you do things you don't really
    > want to do if you are not careful.
    >


    This isn't really what the OP was questioning. That being said, PHP
    isn't *letting* anything happen here. While PHP can tell the difference
    when being called from the command line or web server, it doesn't know
    where in the HTML output it is being called.


    --
    Norman
    Registered Linux user #461062
    -Have you been to www.php.net yet?-
     
    Norman Peelman, Oct 17, 2013
    #9
  10. Tim W

    Tim Streater Guest

    In article <l3n6ou$pcd$>,
    Norman Peelman <> wrote:

    > On 10/16/2013 02:33 PM, William Gill wrote:


    [much stuff snipped]

    > > All this means, you are right it is bonkers, and the example is flawed,
    > > but what it demonstrates is php will let you do things you don't really
    > > want to do if you are not careful.


    It's not bonkers at all, it's simply how it's supposed to work. The idea
    is that you learn to do it right, just as with any programming language
    or environment.

    > This isn't really what the OP was questioning. That being said, PHP
    > isn't *letting* anything happen here. While PHP can tell the difference
    > when being called from the command line or web server, it doesn't know
    > where in the HTML output it is being called.


    The salient point here is that the *whole file* is being processed by
    php. Simply that anything outside the <?php ?> tags is read by php and
    sent straight to the output without modification. Anything *inside* is
    treated as php code and executed. That may or may not result in more
    text being sent to the output *at the point where that text is
    generated* by, f'rinstance, a php echo statement.

    --
    Tim

    "That excessive bail ought not to be required, nor excessive fines imposed,
    nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
     
    Tim Streater, Oct 17, 2013
    #10
  11. On Sat, 12 Oct 2013 22:19:04 +0100, Tim W wrote:

    > Thanks. so it doesn't matter much in the context of that php tutorial
    > except that it would be a very bizarre way of actually doing a real
    > production page with a script on it.


    Actually it matters very much, because it is from such tutorials that
    some of the most pig headed and obstinate idiots on the internet get
    their coding skills, and once they have latched onto a wrong thing, such
    as interleaved tags are OK, they never give up on that thing.

    --
    Denis McMahon,
     
    Denis McMahon, Oct 17, 2013
    #11
  12. Tim W

    Tim W Guest

    On 17/10/2013 11:41, Denis McMahon wrote:
    > On Sat, 12 Oct 2013 22:19:04 +0100, Tim W wrote:
    >
    >> Thanks. so it doesn't matter much in the context of that php tutorial
    >> except that it would be a very bizarre way of actually doing a real
    >> production page with a script on it.

    >
    > Actually it matters very much, because it is from such tutorials that
    > some of the most pig headed and obstinate idiots on the internet get
    > their coding skills, and once they have latched onto a wrong thing, such
    > as interleaved tags are OK, they never give up on that thing.
    >


    Yeah, the kinds of people who stand on right on escalators and don't
    rewind the VHS tape before returning it to the shop.

    tim W
     
    Tim W, Oct 17, 2013
    #12
  13. Tim W <> writes:

    > On 17/10/2013 11:41, Denis McMahon wrote:
    >> On Sat, 12 Oct 2013 22:19:04 +0100, Tim W wrote:
    >>
    >>> Thanks. so it doesn't matter much in the context of that php tutorial
    >>> except that it would be a very bizarre way of actually doing a real
    >>> production page with a script on it.

    >>
    >> Actually it matters very much, because it is from such tutorials that
    >> some of the most pig headed and obstinate idiots on the internet get
    >> their coding skills, and once they have latched onto a wrong thing, such
    >> as interleaved tags are OK, they never give up on that thing.
    >>

    >
    > Yeah, the kinds of people who stand on right on escalators


    Have I been doing it wrong?
    http://blog.ltmuseum.co.uk/wp-content/uploads/2013/06/Fougasse1944.jpg

    > and don't rewind the VHS tape before returning it to the shop.


    <shudder> What that like not closing the grape scissors?

    --
    Ben.
     
    Ben Bacarisse, Oct 17, 2013
    #13
  14. Tim W

    William Gill Guest

    On 10/16/2013 7:16 PM, Norman Peelman wrote:
    > This isn't really what the OP was questioning.That being said, PHP
    > isn't *letting* anything happen here. While PHP can tell the difference
    > when being called from the command line or web server, it doesn't know
    > where in the HTML output it is being called.
    >

    I was a little unsure myself, if he was more concerned about the PHP
    placing content in an invalid location, or the author of the tutorial
    coding erroneous HTML, but since he said he was very new to PHP I tried
    to clarify what PHP did and what the author did.

    Yes, PHP will "let" you do a lot of things that don't violate PHP, but
    may violate the rules of the end user of its output, in this case HTML.

    "PHP is a widely-used general-purpose scripting language..." which means
    output can be used in any number of applications. I frequently use it
    to process text having nothing to do with HTML. The point being, PHP
    validates against its own syntax, but not HTML. Just because it is
    frequently used in conjunction with HTML, or more specifically to
    produce HTML documents, don't ask PHP to do something you shouldn't,
    because it will. It's up to the driver to keep the car out of the ditch,
    because it will "let" you if you ask.
     
    William Gill, Oct 17, 2013
    #14
  15. Tim W

    Tim W Guest

    On 17/10/2013 18:06, William Gill wrote:
    > On 10/16/2013 7:16 PM, Norman Peelman wrote:
    >> This isn't really what the OP was questioning.That being said, PHP
    >> isn't *letting* anything happen here. While PHP can tell the difference
    >> when being called from the command line or web server, it doesn't know
    >> where in the HTML output it is being called.
    >>

    > I was a little unsure myself, if he was more concerned about the PHP
    > placing content in an invalid location, or the author of the tutorial
    > coding erroneous HTML, but since he said he was very new to PHP I tried
    > to clarify what PHP did and what the author did.
    >
    > Yes, PHP will "let" you do a lot of things that don't violate PHP, but
    > may violate the rules of the end user of its output, in this case HTML.
    >
    > "PHP is a widely-used general-purpose scripting language..." which means
    > output can be used in any number of applications. I frequently use it
    > to process text having nothing to do with HTML. The point being, PHP
    > validates against its own syntax, but not HTML. Just because it is
    > frequently used in conjunction with HTML, or more specifically to
    > produce HTML documents, don't ask PHP to do something you shouldn't,
    > because it will. It's up to the driver to keep the car out of the ditch,
    > because it will "let" you if you ask.
    >
    >

    thanks, I understand all that. It wasn't a php question, but an html
    question, because I had never seen anyone put content in the head
    section, was suprised it was even displayed and wondered if there could
    ever be a good reason for it.

    Tim w
     
    Tim W, Oct 17, 2013
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian W
    Replies:
    10
    Views:
    792
    Brian W
    Jul 2, 2003
  2. showme

    PHP and ASP.NET go HEAD to HEAD

    showme, Jul 8, 2004, in forum: ASP .Net
    Replies:
    13
    Views:
    747
    Sherif ElMetainy
    Jul 10, 2004
  3. Rick
    Replies:
    3
    Views:
    541
    bruce barker \(sqlwork.com\)
    May 10, 2006
  4. Rolf Welskes
    Replies:
    7
    Views:
    976
    Steven Cheng[MSFT]
    Aug 22, 2006
  5. Jiho Han

    Write into <HEAD></HEAD> section?

    Jiho Han, Jan 14, 2004, in forum: ASP .Net Building Controls
    Replies:
    6
    Views:
    242
    Sam Fields
    Jan 16, 2004
Loading...

Share This Page