Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2005
    Location
    New York
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    The DOCTYPE on a PHP page ?

    Hi guys,

    The DOCTYPE is supposed to go at the very top, before anything. But at the same time, if I use a header('Location: SomePage.htm'); it has to be used before anything is sent. So how do I do it ?

    MyPage.php

    // DOCTYPE here ?

    if(someCondition){
    header('Location: SomePage.htm');
    }

    // DOCTYPE here instead ?

    rest of my page
    ...
    ...

    I don't get it. I think having it after the conditional is correct but am really not sure. If it's at the very top does that mean something was sent to the browser before the conditional (meaning the header() is incorrect) ?

    Thanks.

  • #2
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    if(someCondition){
    header('Location: SomePage.htm');
    }

    // DOCTYPE here instead ?

    would be right as the doctype only has to be at the top of your output and header runs a command but does not output content so your client end page would still have doctype at the top.

    Although i havn't tested if it was before the header i would expect it to bounce.

    Hope this helps.
    Mike

  • #3
    Regular Coder
    Join Date
    Oct 2004
    Posts
    360
    Thanks
    0
    Thanked 17 Times in 17 Posts
    The doctype should go before any html output, PHP can go before it as long as it's not printing/echoing anything out.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •