Cannot send session cache limiter - headers (solved)

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
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Cannot send session cache limiter - headers (solved)

Post 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.
Last edited by Bigun on Tue Jun 13, 2006 3:40 pm, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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
(#10850)
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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().
(#10850)
t_catt11
Forum Newbie
Posts: 5
Joined: Tue Jun 13, 2006 2:40 pm
Location: Birmingham, Alabama

session stuff

Post 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.
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post 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.
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

So what is on lines 1-4?
(#10850)
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post 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.
Post Reply