Jump to content

session_start()


leequalls

Recommended Posts

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();

 

 

Link to comment
https://forums.phpfreaks.com/topic/210809-session_start/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/210809-session_start/#findComment-1099664
Share on other sites

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>

 

Link to comment
https://forums.phpfreaks.com/topic/210809-session_start/#findComment-1099665
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.