doubledee Posted March 9, 2012 Share Posted March 9, 2012 Does starting a Session send data to the Header? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/ Share on other sites More sharing options...
scootstah Posted March 9, 2012 Share Posted March 9, 2012 What do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325549 Share on other sites More sharing options...
doubledee Posted March 9, 2012 Author Share Posted March 9, 2012 What do you mean? I was wrapping up functionality that updates "last_activity" in MySQL whenever a User does something on my website so that I can keep their "Online Status" near real-time. I broke something, and now I am getting the famous "Data already send to Headers"!! Trying to trouble shoot. Maybe I should start a more aptly labeled thread about this problem? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325553 Share on other sites More sharing options...
cpd Posted March 9, 2012 Share Posted March 9, 2012 All you have to do is ensure you do not output any data before you begin the session. Setting variables is fine but if you say "echo" or anything and the try to start the session it will fail. Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325554 Share on other sites More sharing options...
Psycho Posted March 9, 2012 Share Posted March 9, 2012 This is the error you will receive when attempting to send output to the browser before starting the session Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\test\test.php:3) in C:\xampp\htdocs\test\test.php on line 5 So, the error seems pretty obvious to me. FYI: that took me all of 2 minutes to test. //Comment/uncomment to test the difference //echo "Start the session"; session_start(); echo "Session started"; Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325557 Share on other sites More sharing options...
doubledee Posted March 9, 2012 Author Share Posted March 9, 2012 Don't minimalize my problem. If it was that easy I wouldn't be asking for help... I'll start a new thread describing this problem which is between several scripts. Debbie Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325563 Share on other sites More sharing options...
xyph Posted March 9, 2012 Share Posted March 9, 2012 To sum it up, no it does not. It modifies the headers being sent, but it doesn't actually output anything. Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325565 Share on other sites More sharing options...
doubledee Posted March 9, 2012 Author Share Posted March 9, 2012 To sum it up, no it does not. It modifies the headers being sent, but it doesn't actually output anything. That is what I thought. Grrrr.... I fear this is going to be one of those "Bugs from Hell" to chase down?! I am testing and getting sporadic results. Will post more soon... Debbie Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325567 Share on other sites More sharing options...
Adam Posted March 9, 2012 Share Posted March 9, 2012 The 'headers already sent' error tells you where the output is started: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\test\test.php:3) in C:\xampp\htdocs\test\test.php on line 5 Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325570 Share on other sites More sharing options...
Psycho Posted March 9, 2012 Share Posted March 9, 2012 Don't minimalize my problem. If it was that easy I wouldn't be asking for help... I'll start a new thread describing this problem which is between several scripts. Who is minimizing your problem? I simply showed the error that would be displayed if you attempted to output to the browser before starting the session. If that was the error you had received you should have known that the problem was with the problem was with the position at which the session was started. However, I also pointed out that it would have taken less time to verify that for yourself rather than posting a topic on the forum. To paraphrase what you have told others - If you don't like my responses, don't post stupid questions for me to respond to. Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325573 Share on other sites More sharing options...
doubledee Posted March 9, 2012 Author Share Posted March 9, 2012 To paraphrase what you have told others - If you don't like my responses, don't post stupid questions for me to respond to. Were you not held enough as a child? My must you frequently be so hostile? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325575 Share on other sites More sharing options...
Psycho Posted March 9, 2012 Share Posted March 9, 2012 To paraphrase what you have told others - If you don't like my responses, don't post stupid questions for me to respond to. Were you not held enough as a child? My must you frequently be so hostile? I'm not hostile, I'm just making a statement regarding a person's inability to even attempt simple problem solving techniques. You are the one who just made an unfounded derogatory statement. But, what I believe is that my parents helped me to become an independent person who is able to utilize critical thinking skills to determine when a problem is something I can solve on my own. Plus, my parents taught me not to steal, which is what I would be doing if I utilized someone's copyrighted photo as my avatar. Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325580 Share on other sites More sharing options...
cpd Posted March 9, 2012 Share Posted March 9, 2012 This is an unnecessary argument chaps. The problem has been clearly explained by Psycho with a perfect example. Your actual problem may seem far more complex but ultimately will boil down to you starting a session after outputting something to the browser. As pointed out by xyph, the code should indicate where the error is coming from. To thoroughly debug your script try killing it at different steps of the execution using: echo "Hello World"; die; Then you'll be able to determine at what stage things are going wrong. Just a suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/258594-header-and-session/#findComment-1325587 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.