...

View Full Version : The DOCTYPE on a PHP page ?



Emperor
07-06-2005, 06:13 PM
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.

anarchy3200
07-06-2005, 06:19 PM
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.

schleppel
07-06-2005, 06:22 PM
The doctype should go before any html output, PHP can go before it as long as it's not printing/echoing anything out.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum