E_Leeder Posted February 12, 2014 Share Posted February 12, 2014 I'm trying to diagnose headers already sent errors. I know that I can see the line and comment it out (or do something) based on the error given, but what I don't understand is why they seem to occur sometimes but not others. The code below sends things to the browser before calling session_regenerate_id(true), which will cause headers already sent errors if headers have already been sent. <?php echo 'hello world'; $test_variable = 'some variable to var_dump'; var_dump($test_variable); session_regenerate_id(); ?> I thought that this should fail and give me a headers already sent error, but it doesn't. I frequently echo to a page before calling a header action, and sometimes it works, sometimes it doesn't, like in the case above. What's going on to give me an error elsewhere but not here? Quote Link to comment https://forums.phpfreaks.com/topic/286143-diagnosing-headers-already-sent-errors/ Share on other sites More sharing options...
.josh Posted February 12, 2014 Share Posted February 12, 2014 Is your experience in testing/developing, in different environments, e.g working locally with wamp or xampp or something vs. a hosted server, or multiple hosted servers? Because the most common cause is that it depends on what the error reporting levels are set at, either in the php.ini file or in some script itself. Quote Link to comment https://forums.phpfreaks.com/topic/286143-diagnosing-headers-already-sent-errors/#findComment-1468659 Share on other sites More sharing options...
E_Leeder Posted February 13, 2014 Author Share Posted February 13, 2014 (edited) I am in a dev environment with all errors on (I think... the setting is: error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT)). Does the code I posted cause an error for you? (Other things cause me headers already sent errors.) Edited February 13, 2014 by E_Leeder Quote Link to comment https://forums.phpfreaks.com/topic/286143-diagnosing-headers-already-sent-errors/#findComment-1468697 Share on other sites More sharing options...
.josh Posted February 13, 2014 Share Posted February 13, 2014 Yes, I get a headers already sent error. Do you sometimes use output buffering in your script (e.g. use ob_start)? Quote Link to comment https://forums.phpfreaks.com/topic/286143-diagnosing-headers-already-sent-errors/#findComment-1468717 Share on other sites More sharing options...
Ch0cu3r Posted February 13, 2014 Share Posted February 13, 2014 You may also want to check in your php.ini that output_buffering is set to Off. Quote Link to comment https://forums.phpfreaks.com/topic/286143-diagnosing-headers-already-sent-errors/#findComment-1468718 Share on other sites More sharing options...
E_Leeder Posted February 14, 2014 Author Share Posted February 14, 2014 You were right, output buffering was turned on. I turned it off, and received the error. Thanks for that. Quote Link to comment https://forums.phpfreaks.com/topic/286143-diagnosing-headers-already-sent-errors/#findComment-1468826 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.