Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Getting a warning from using DOCTYPE?

Hi, I'm currently using
Code
print "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
    'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
at the top of my file,
but after moving host, it's starting causing some errors.
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/royalbat/public_html/explore.php:22) in /home/royalbat/public_html/explore.php on line 23

If I removed the doctype line the session_start(); stops causing an error, but it messes up how the HTML is parsed on the page and it doesn't display properly.

Any ideas on how I fix this? I really need a fix for this soon, thanks!

EDIT:
Turns out,
Like editing header information after text has been sent, you can't do it with session_start() either,
I simply put the session_start before the <!DOCTYPE> and it worked perfectly!
Why don't you use template power? much better.
if you need any help add me on skype: hypzxiwan
It's good that you found your solution, however you may not fully understand why the error occurred, and why your fix worked. So here's a quick explanation.

The session_start() function will, by default, use cookies to store the unique session identifier in (unless stated otherwise, in which case it will be passed in the URI via the query string). Because cookies are apart of the HTTP header, they must be sent out before any content has been output to the browser. This means that when invoking the session_start() function, it must be done at the start of the script, preferably before any other php code (because any error caused by preceeding php code will be output on the screen, and will therefore trigger the header error you saw above).

Therefore, by placing the HTML code below the session_start() function, we prevent the header error. By changing host, your php error reporting level was most probably changed to output warnings, hence why you saw the error only on your new host. I personally would advise you to always work on the highest possible error reporting level to ensure php isn't surpressing them (impacting performance and giving the potential for bugs to creep in).
PHP internals developer


Possibly Related Threads...
Thread / Author Replies Views Last Post
by NessieJul 22, 2012 08:04 PM 4 115 Jul 22, 2012 08:04 PM
Last Post: Dylan Wins
by [H]ellFeb 23, 2012 05:15 AM 3 106 Feb 23, 2012 05:15 AM
Last Post: YERANUK
by theAbsoluteNov 24, 2011 08:52 AM 2 110 Nov 24, 2011 08:52 AM
Last Post: theAbsolute