Best way to layout code?

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
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Best way to layout code?

Post 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
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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.
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post 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.
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Re: Best way to layout code?

Post 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();
Post Reply