Re: user login and access + headers already sent
| From: | Richard Quadling | Date: | Thu, 15 Jul 2010 15:50:37 +0000 |
| Subject: | Re: user login and access + headers already sent | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-306917@lists.php.net to get a copy of this message | ||
On 15 July 2010 16:38, Carlos Sura <carlos_sura@hotmail.com> 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?
> Because, almost every page contains javascript, so almost every 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.
The quick and dirty way is to use output buffering - [1].
The better way is to use includes/requires - [2]. This will involve
moving code around the system, extracting common parts and then
"include"-ing them in the right place.
Also, a common practise is to only have output generated at the end of
the script, rather than using a lot of echo's through out the code. A
sort of manual output buffering.
Regards,
Richard Quadling.
[1] http://docs.php.net/manual/en/book.outcontrol.php
[2] http://docs.php.net/manual/en/language.control-structures.php
and
look for include/require/include_once/require_once