I have a login script that on successful login performs -
This is not executing. I have investigated and come to the conclusion that it is because the headers have already been sent, probably because I have introduced echoes to output messages to help with debugging. I have added
ob_start(); at the very beginning of the script and
ob_end_flush(); immediately after
This fix works, but am I doing it properly. Is this the best place for
ob_start();, first line of the script or should it maybe come after
session_start();, or somewhere else. And is it ok to
ob_end_flush(); immediately after the
The only reason I am doing this is to get PHP to redirect to the home page. I want to be sure I am using the function correctly, efficiently and not building in other problems for myself. I am completely unfamiliar with buffers and flushing them. It works but am I doing the right thing in the best way.
First of all, I did research this and checked out https://www.sitepoint.com/community/t/when-to-use-ob-start-and-ob-end-flush/5462
This was interesting, but mainly because it ended in a fist fight However I did grasp that it is best to separate output from other processing, which seems like good advice. But when you want to include echoes for help with debugging it makes that difficult. Also the post says start as near the top as possible (although obviously at this point tension was building) -
I appreciate that salathe was not recommending this approach but are there any exceptions to this like after starting a session etc.