Page 1 of 1

Best way to layout code?

Posted: Thu Jul 31, 2003 9:20 pm
by pinehead18
I am writing a website and i have a user login system. I am sending out alot of headers. I have a functions.inc page wich is where i write all the script then on the individual pags i just use function() and reference the specific function. However, i am encountering alot of headers already sent errors.

Does anybody have a better solution for this or can help me on a better way to layout my code?

I thought about ob_start(); but i can't figure out how to use it.

Any help you can provide would be awsome.

Thank you

Anthony

Posted: Thu Jul 31, 2003 10:11 pm
by DuFF
Did you read the pinned topic at the top of this forum? There is one about header files. I read it and it saved me a lot of headaches. Your problem is probably with the whitespace above or below the contents of the header file. Make sure there are no extra spaces or lines in it.

Posted: Sat Aug 02, 2003 11:33 pm
by jmarcv
Thats right. RIGHT at the top. It even says:

Before Post Read: Warning: Cannot add header information

-----------------------------------------
Many can write English, few can read it.

Re: Best way to layout code?

Posted: Sun Aug 03, 2003 3:51 am
by pootergeist
pinehead18 wrote:I am sending out alot of headers
I presume from that line that you are aware of the headers you are sending and I'd guess are using them as conditional redirects (most other headers couldn't be ran as inline code after a http one is sent)

output buffering would be the sensible fix.

<?php
ob_start("ob_gzhandler");

// rest of code - sessions, cookies, db, html output etc.

ob_end_flush();
?>

the ob_gzhandler just compresses the data into a gzip format for the client browser to unzip - leave a blank parameter for no compression ob_start();