PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Can someone please help with this headers already sent problem. I have created a few pages that require users to log in, in order to access the content, I have echoed the page that users should be directed to upon login using
Can someone please help with this headers already sent problem. I have created a few pages that require users to log in, in order to access the content, I have echoed the page that users should be directed to upon login using
but its just not working...im quite new to php so i dont know how to go about troubleshooting this problem. Any suggestions will be welcome. Thanks.
When you use the echo command data is sent out from the server to the browser, and before this data comes the headers, and therefor the headers are also being sent out at the same time. Sessions in PHP use the "Cookie" field in the HTTP Header and therefor require that the header not be sent out when being initiated.
To solve your problem you need to have session_start() as the very first line in your code. You cannot call commands which send output (like echo) before starting session if you intend on using a session.
I think the only alternative is ob_start() which creates an output buffer and doesn't send any data until specified or the script ends. I could be wrong on this though.
I have already encountered this kind of problem. Try to find out any "echo" has been given
by you in your code. If so, try to remove that one because you are redirecting the page,
same time you are echoing something in the current page. It will generate the error. Try
to use - header("Location://path");