Page 1 of 1

Creating libraries for processing before header sent

Posted: Fri Apr 17, 2009 7:47 am
by devweb
Hi all

I'm still learning PHP, I want to know if anyone can explain to me how to create a library of functions etc that I may create. I know that you can have a file called 'lib' for example and then pages call the functions from these files when needed before the header of the page is sent.

I hope someone can shed some light on this for me.

Thanks in advance

DW

Re: Creating libraries for processing before header sent

Posted: Fri Apr 17, 2009 11:15 am
by Christopher
You don't need to get your PHP scripts any special names, such as 'lib', they can be named anything. The term "headers sent" refers to the fact that if script outputs anything (even a space character) then PHP will first sent any HTTP headers it sends by default or that you have added. So you cannot sent output and then call the header() function because the output cause the HTTP headers to already be sent.

Just put your PHP code before output occurs, or gather output in a variable and echo it at the end of the script.