Hack Forums
Getting a warning from using DOCTYPE? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Webmasters (https://hackforums.net/forumdisplay.php?fid=141)
+---- Forum: Website Construction (https://hackforums.net/forumdisplay.php?fid=50)
+---- Thread: Getting a warning from using DOCTYPE? (/showthread.php?tid=3222050)



Getting a warning from using DOCTYPE? - Sir Paul McCartney - Jan 31, 2013

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!


* - kaaskop - Jan 31, 2013

Why don't you use template power? much better.
if you need any help add me on skype: hypzxiwan


* - Haxalot - Jan 31, 2013

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).