Web Hosting Talk







View Full Version : Header() Php


manytopsites
10-29-2007, 11:03 PM
The one that can explain what tics behind this function in laymans terms is my hero, hehe, been trying to make a login script in php, and the only thing not working is the header() function, the problem is that i cant get both the script and the header function to work together, and tried buffering my output with the bufferfunction, and how does that effect the flow of code?? does the code inside the buffer run before it lets it out, or does it run afterwards,,, ps, i do know that i must have header() in the start before all the code and stuff,,

spt1224
10-29-2007, 11:43 PM
Basically, output buffering prevents any output from being sent from the page except for headers, until you tell explicitly tell the buffer to output its contents.

So, the flow of code is unaffected. The code is still executed in exactly the same order, it's just that the only thing that gets outputted is the headers until you flush the buffer with ob_end_flush() or some similar function.

i do know that i must have header() in the start before all the code and stuff
Actually, that's the whole point of buffering, to make that unnecessary.

bigfan
10-30-2007, 02:55 PM
Just to clarify: The response header is sent at the same time as the contents of the buffer (or with the initial output if unbuffered), although its Date: header will show the time the http request was received.

nnormal
10-31-2007, 10:03 AM
ob_start() will not effect performance unless the server running it is very crappy or the html output is very large. Even if both of those are true the page will still finish loading at about the same time. It will just start to load sooner with ob off. You can also use ob_end_flush() right after your header call if you are that concerned. This will buffer everything up to the header() call then output normally (unbuffered) after that point.