WARNING: session_start() [function.session-start]

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
dev646
Forum Newbie
Posts: 2
Joined: Fri Oct 31, 2008 6:08 am

WARNING: session_start() [function.session-start]

Post by dev646 »

WARNING: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent...

this is what i get for a captcha checking code which goes like...

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
    font-size: 12pt;
    font-weight: bold;
}
-->
</style>
</head>
</script>
 
<body>
<td>
<?php 
   session_start();
   if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) 
   {
      // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
      unset($_SESSION['security_code']);
      echo '<h1>correct !</h1>';
   } 
   
   else 
   {
      // Insert your code for showing an error message here
      echo '<h1>WRONG !!! </h1>';
   }
?>
<form id="form1" name="form1" method="post" action="">
  <p><img src="../includes/CaptchaSecurityImages.php" /> <span class="style1">Type the Security Code you see to the left ,HERE ~~~> </span>
      <input id="security_code" name="security_code" type="text" />
      <input type="submit" name="Submit" value="Submit" />
  </p>
</form>
</td>
</body>
</html>
 
help needed... why is this coming and how to solve this ???
 :) 
 
 
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: WARNING: session_start() [function.session-start]

Post by Mark Baker »

It's happening because you've already generated browser output before the session_start() statement in your code. session_start() needs to modify the http response headers

move your session start above the <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> line

Code: Select all

 
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
...
 
Post Reply