leequalls Posted August 15, 2010 Share Posted August 15, 2010 My code seems to be working correctly however I get the following error Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/party/public_html/en/header.php:12) in /home/party/public_html/en/requests.php on line 36 is there a way to fix this message or keep it from displaying the code is below form: <img src="captcha/index.php" width="120" height="30" border="1" alt="CAPTCHA"></p> <p><input type="text" size="6" maxlength="5" name="captcha" value=""><br> <small>copy the digits from the image into this box</small></p> captcha/index.php <?PHP // Adapted for The Art of Web: www.the-art-of-web.com // Based on PHP code from: php.webmaster-kit.com // Please acknowledge use of this code by including this header. // initialise image with dimensions of 120 x 30 pixels $image = @imagecreatetruecolor(120, 30) or die("Cannot Initialize new GD image stream"); // set background and allocate drawing colours $background = imagecolorallocate($image, 0x66, 0x99, 0x66); imagefill($image, 0, 0, $background); $linecolor = imagecolorallocate($image, 0x99, 0xCC, 0x99); $textcolor1 = imagecolorallocate($image, 0x00, 0x00, 0x00); $textcolor2 = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); // draw random lines on canvas for($i=0; $i < 6; $i++) { imagesetthickness($image, rand(1,3)); imageline($image, 0, rand(0,30), 120, rand(0,30) , $linecolor); } session_name("captcha"); session_start(); // add random digits to canvas using random black/white colour $digit = ''; for($x = 15; $x <= 95; $x += 20) { $textcolor = (rand() % 2) ? $textcolor1 : $textcolor2; $digit .= ($num = rand(0, 9)); imagechar($image, rand(3, 5), $x, rand(2, 14), $num, $textcolor); } // record digits in session variable $_SESSION['digit'] = $digit; // display image and clean up header('Content-type: image/png'); imagepng($image); imagedestroy($image); ?> after form is submitted: session_start(); if($_POST['captcha'] != $_SESSION['digit']) { echo "<p><b>--Sorry, the CAPTCHA code entered was incorrect!--</b><p>"; } else { $query = "INSERT INTO rp_request (name, type, request, ipaddr, time) VALUES('$name','$type','$request','$ipaddr','$time')"; mysql_query($query) or die(mysql_error()); echo "<p><b>--Your Request Has Been Sent--</b><p>";} session_destroy(); Quote Link to comment https://forums.phpfreaks.com/topic/210809-session_start/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 15, 2010 Share Posted August 15, 2010 output started at /home/party/public_html/en/header.php:12 (line 12) is there a way to fix this Yes, look at line 12 of header.php and find what output it is sending at or before that point and eliminate that output as it is preventing the session_start() from working. Alternatively, you can move the session_start() statement so that is occurs before you send any output to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/210809-session_start/#findComment-1099664 Share on other sites More sharing options...
leequalls Posted August 15, 2010 Author Share Posted August 15, 2010 this is whats at line 12 on header.php <style type="text/css"> #ajax-banner { border: 0px; width: 582px; height: 99px; text-align: left; } </style> Quote Link to comment https://forums.phpfreaks.com/topic/210809-session_start/#findComment-1099665 Share on other sites More sharing options...
PFMaBiSmAd Posted August 15, 2010 Share Posted August 15, 2010 That's all HTML that is output to the browser. Outputting any characters to the browser prevents the HTTP header that is need for session_start(). Quote Link to comment https://forums.phpfreaks.com/topic/210809-session_start/#findComment-1099668 Share on other sites More sharing options...
leequalls Posted August 15, 2010 Author Share Posted August 15, 2010 putting the session_start before header.php worked the message does not show now. thanks Quote Link to comment https://forums.phpfreaks.com/topic/210809-session_start/#findComment-1099671 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.