Hello paul, thank you for your answer.
I'm already fixing all my mess with your suggestions.
It is nice to know where to ask to get a good answer.
> Date: Thu, 15 Jul 2010 12:22:23 -0400
> From: pa...@quillandmouse.com
> To: firstname.lastname@example.org
> Subject: Re: [PHP] user login and access + headers already sent
> On Thu, Jul 15, 2010 at 04:56:50PM +0100, Ashley Sheridan wrote:
> > On Thu, 2010-07-15 at 15:38 +0000, Carlos Sura wrote:
> > > Hello mates, I'm developing a user registration and access level system...
> > >
> > > And I wonder... Is there any way to avoid to put code in every header
> > > page?
> > page cotains <html> tags... And its annoying to look at this: Warning:
> > session_start(): Cannot send session cache limiter - headers already sent
> > >
> > > So, I'm wondering, is there any other way to avoid put code in every
> > page? or... another way to avoid that kind of error.
> > >
> > >
> > > Thank you.
> > >
> > > _________________________________________________________________
> > > Got a cool Hotmail story? Tell us now
> > > http://clk.atdmt.com/UKM/go/195013117/direct/01/
> > A key concept to remember is that HTML is inserted into your PHP code,
> > and not the other way around. Once I realised the difference, I found I
> > was making the header/output mistake far less often.
> > Anyway, to answer the question, what most apps/websites do for this is
> > to use controller code to load in the correct HTML as necessary. The
> > first lines of most of my apps are general include lines. One for DB,
> > one for other config, etc. That way, I can just use the include files
> > for doing things that need to be done for every page.
> > Common logic for a login is to use an include file that does this:
> > 1. Is user logged in? Yes: goto 5. No: goto 2
> > 2. Have login details been submitted through form or other? Yes:
> > goto 3. No: goto 4
> > 3. Are login details correct? Yes: goto 5, No: goto 4
> > 4. Show login form & stop
> > 5. Show/redirect to app page
> > (apologies for the hard to follow list, but I just realised I don't know
> > a good way to show a flowchart in plain text!)
> > Use include files for your HTML headers, and only include them after
> > you've done everything you need to with session_start() and header()
> > calls. If there's content that changes in the header from page to page,
> > put that in a variable that you use in the included file.
> Let me amplify this by suggesting that you minimize the PHP code inside
> your HTML. Like this:
> 1. Load your main PHP file. Do any calculations, etc., in it.
> 2. At the end of that file, load in a generic HTML template file. This
> file would contain everything from the <html> tag to the </html> tag.
> 3. Inside your template file, make a call to a "view" file, which is
> unique for this page. It should contain all the HTML code outside the
> actual template. In this file, make whatever PHP code limited to echoing
> values and loops. The values displayed, etc., are formulated in the
> original PHP file.
> That's one way to do it.
> Paul M. Foster
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
We want to hear all your funny, exciting and crazy Hotmail stories. Tell us now