Sunday, May 13, 2012

Header function not working in PHP? - Solved





While programming in PHP, you may use header() function occassionaly whenever you want to use a 302 redirect. Well, header() function in PHP has some sort of exceptions. Its should meet those criterias in order to get executed.



One of such exception is that there should not be any echo or print statement before any header() statement. If there is, header() function will not work. This is the most common error which many user face, and even I faced it, after which, I wrote this small post.

So, how to make header function to work after echo or print statement?





Well solution is pretty simple. For this, you just need to put output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.



To start output buffer simply write down the following statement in the begening of your PHP code:



ob_start()


That's it. You are done!

Tags: ,

0 Responses to “Header function not working in PHP? - Solved”

Post a Comment

Subscribe

Donec sed odio dui. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio. Duis mollis

© 2013 Coolpctips. All rights reserved.
Designed by SpicyTricks