Creating libraries for processing before header sent

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!

Moderator: General Moderators

Post Reply
devweb
Forum Newbie
Posts: 1
Joined: Fri Apr 17, 2009 7:44 am

Creating libraries for processing before header sent

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Creating libraries for processing before header sent

Post 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.
(#10850)
Post Reply