Page 1 of 1

Cannot send session cache limiter - headers (solved)

Posted: Tue Jun 13, 2006 2:42 pm
by Bigun
I'm trying to add some Captcha to my newuser form.

Here's the snippet that should take care of that:

Code: Select all

function audit() {
                session_start();
                $digit = $_SESSION['digit'];
                $userdigit = $_POST['userdigit'];
                session_destroy();
                if (($digit == $userdigit) && ($digit > 1)) {
                        return true;
                } else {
                        return false;
                }
        }

        if (audit()) {
        } else {
                echo "<center><font color=red><b>Please type in the correct text from the picture into the box below</b></font></center><br>";
                $failed = "yes";
        }
If the user enters the code correctly, the page works beautifully. But if the incorrect captcha code is loaded, this ugly code shows up:

Code: Select all

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/cybergru/public_html/test/newuser.php:13) in /home/cybergru/public_html/test/newuser.php on line 48
Any suggestions on fixing this?

*EDIT*

BTW, line 48 is that session_start() code snippet.

Posted: Tue Jun 13, 2006 2:47 pm
by Christopher
A tempting place to start would be somewhere before:

Code: Select all

in /home/cybergru/public_html/test/newuser.php on line 48

Posted: Tue Jun 13, 2006 2:52 pm
by Bigun
arborint wrote:A tempting place to start would be somewhere before:

Code: Select all

in /home/cybergru/public_html/test/newuser.php on line 48
Yes, I kinda figured.

I ammended my initial post with the explaination of what that line was.

But I'll repeat:

It's the session_start() line listed above. But it's immediately destroyed 3 lines later.

Posted: Tue Jun 13, 2006 3:01 pm
by Christopher
Right, but the error says:

Code: Select all

headers already sent (output started at /home/cybergru/public_html/test/newuser.php:13)
That means that there was some output before you did the session_start(). It could be a space or anything. This is a really common error with sessions -- no output is allowed before session_start().

session stuff

Posted: Tue Jun 13, 2006 3:02 pm
by t_catt11
Session headers - in fact, heads of ANY kind - can only be added before anything whatsoever - even blank spaces - are output to the screen. If you have sent the HTML tag, you'll gett his error. If you have left whitespace before the HTML tag, you'll get this error.

Posted: Tue Jun 13, 2006 3:12 pm
by Bigun
Ok, I moved this function to the beginning of the PHP file.

It gives the same error, only now complaining about line 4.

Posted: Tue Jun 13, 2006 3:16 pm
by Bigun
O.o

However, I just moved the code that calls that function to the top of the page (before any output), and I don't get any errors.

Posted: Tue Jun 13, 2006 3:16 pm
by Christopher
So what is on lines 1-4?

Posted: Tue Jun 13, 2006 3:40 pm
by Bigun
arborint wrote:So what is on lines 1-4?
I got it, it seems the code for the session_start() can go anywhere, but it needs to be called before any output.