Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ambiguous error message

Status
Not open for further replies.

vcherubini

Programmer
May 29, 2000
527
US
Hello:

I am working with session management and I keep getting the same error:

Warning: Cannot send session cache limiter - headers already sent (output started at lib.inc.php:233) in c:\apache\htdocs\mobius\login.php on line 6.

login.php looks like this:

[tt]
<?php
include(&quot;lib.inc.php&quot;);
connect();
login(&quot;SELECT * FROM users WHERE username='$username' AND password='$password'&quot;);
back();
session_start();
session_register(&quot;username&quot;);

?>
[/tt]

What I want to happen is when a user types his/her password in on index.php, it will authenticate them (that part works fine) and then register the variables $username and $password so that I can use them throughout the remainder of the user session on my site.

Any help on how I can get this to work would be greatly appreciated.

Thanks.

-Vic
vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
I found the err of my way.

The session functions must be before anything is printed to the browser.

I just put them at the top of the script and it works fine.

Thanks.

-Vic vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
Yes, normally headers (which are used by sessions) cannot be sent if any other output has already started sending to the browser, because well... a header means it comes *before* output, and PHP/Apache automatically stick a header on everything, the minute any output begins. There is a way around this, though, and it's worth checking out, because it can provide some major clues for writing more complex web-based apps. It's called Output Buffering. See
It is what it sounds like. It buffers the output until the script is finished, checking for any header calls, and handling them first, among other things.
 
rycamor:

Thanks a lot for that! I will definitely check that site out.

-Vic vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top