Dressing up jeoroen's comment:
Just because you might have written <?php session_start();
right at the start of a file, doesn't necessarily mean it's the beginning of the script! As shown by your error, you have output beginning in home.php
at line 105. Perhaps you have some header stuff there, then you called include login.php;
to begin session stuff.
While "nothing must come before it" is a good rule of thumb, the more accurate rule is "the script must not send output before it". Personally, I have session_start()
called two layers of included files deep and even then it's somewhere around line 60 (making games means I have a LOT of init code!) but output does not begin until after all code has run - in fact, in my latest project the very last line of code to run is $template->output();
, a function which takes all of the work done so far and dresses it up in all the HTML it needs.
That last point is actually quite important. Many people, especially experienced programmers, will emphasise the importance of separating your layers. At its simplest, use external CSS and JS files instead of inlining stuff in your HTML, to separate content from style from functionality. The same applies to PHP. Ideally you should avoid outputting HTML willy-nilly in your code, instead your code should do all the processing it needs and then output it at the end.
Smarty is a widely-used engine for this, but in that project I mentioned earlier $template->output()
just creates a clean function scope, imports the prepared data, and calls require $file.".tpl.php";
so I can have some final post-processing. I figured that was easier than installing an entire third-party engine :p I... I have trust issues with code other people wrote. Years ago, I lost gigabytes of forum posts to a glitch in phpBB... -shivers-
Anyway, hope this rambling helps!