Forum Moderators: coopster

Message Too Old, No Replies

weird headers already sent error

         

generic

4:41 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



Hi all,

I'm working on a CAPTCHA script and I keep getting this error:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /mnt/w0302/d47/s14/b00686a8/www/v2/contact.php:1) in /mnt/w0302/d47/s14/b00686a8/www/v2/contact.php on line 2

I know this means I've probably got whitespace or I didn't start my session on the first line, but I've gone over this for several hours now and everything is where it should be, but I can't get rid of the error. I've tried every conceivable combination all to no avail. The funny thing is that aside from the error, the script itself works totally fine! I've tried eliminating the error with ob_flush but that doesn't work for me either so I'm at a total loss. Here's what I've got for code:

../contact.php
-----------------
<?php
session_start();
$p = "contact";
include('includes/header.php');
?>
<body>
... HTML HERE ...
<?php
if(isset($_POST['secure'])) {
if($_POST['secure'] != $_SESSION['security_number']) {
$error = "Failed";
} else {
$error = "Passed";
}
}
?>
<form method="POST">
<input type="text" name="secure"><input type="submit" value="check"><br>
<img src="includes/captcha.php">
</form>
<?=$error?>
...MORE HTML ...

includes/captcha.php
--------------------
<?php
session_start();
$operators=array('+','-');
$first_num=rand(1,5);
$second_num=rand(6,11);
shuffle($operators);
$expression=$second_num.$operators[0].$first_num;

eval("\$session_var=".$second_num.$operators[0].$first_num.";");

$_SESSION['security_number']=$session_var;

$img=imagecreate(100,50);

$text_color = imagecolorallocate($img,255,255,255);
$background_color= imagecolorallocate($img,0,0,0);

imagefill($img,0,150,$background_color);
imagettftext($img,16,rand(-10,10),rand(10,30),rand(25,35),$background_color,"../fonts/courbd.ttf",$expression);

header("Content-type:image/jpeg");
header("Content-Disposition:inline ; filename=secure.jpg");
imagejpeg($img);
?>

Thanks in advance for any help, I've literally been up all night with this and it's probably something ridiculously simple...

gen

jatar_k

6:26 pm on Mar 10, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try copying it to a new file all together, smells of the old phantom char from a mac edited file

generic

6:37 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



Wow, that's amazing! That was quite possibly the worst several hours I've spent in the last few years... I didn't even know that issue existed. Anyway, fifteen million virtual beers for you jatar_k - that solved it right quick.

Thanks,

gen

jatar_k

7:25 pm on Mar 10, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



my pleasure

it pops up now and again, whenever someone seems to already understand the "extra line before the php tag" then this is my next step. Discovered it long ago and has saved a lot of headaches ever since. ;)