how can i fix this error Cannot send session cache limiter - headers already sent

Discussion in 'PHP' started by mahacan, Oct 18, 2008.

  1. #1
    hey guys,

    please somebody help me.

    I get this error from my script


    Warning: session_start() [function.session-start.php]: Cannot send session cache limiter - headers already sent (output started at D:\mydomain.com\wwwroot\user\login.php:1) in D:\mydomain.com\wwwroot\user\login.php on line 1
    
    Warning: session_start() [function.session-start.php]: Cannot send session cache limiter - headers already sent (output started at D:\mydomain.com\wwwroot\user\login.php:1) in D:\mydomain.com\wwwroot\user\login.php on line 6



    login.php page is:
    
    <? session_start();
    include("functions.php");
    if($login == 'yes')
    {
    	session_destroy();
    	session_start();
    	$_SESSION['username'] = $username;
    	$_SESSION['password'] = $password;
    }
    
    top();
    
    //IF THERE IS NO USERNAME FROM A FORM CHECK IF ITS IN THE SESSION
    if($username == $admin_username & $password == $admin_password)
    	{
    	$_SESSION['username'] = $username;
    	$_SESSION['password'] = $password;
    	?> <font size="2" face="Arial, Helvetica, sans-serif">Hi <? echo $admin_firstname; ?>! Now loading administration 
    applications...
    </font> 
    <script language="JavaScript">
    	location="admin.php";
    	</script>
    	<?
    	bottom();
    	die();
    } 
    
    //SCAN USERS AND PASSWORDS
    $link=mysql_connect ("NEON", $admin_mysqluser, $admin_db_pass) or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ($admin_database, $link) or die("Error selecting database. Server may be down try again in a few minutes.");
    $query = "SELECT * FROM client_list WHERE username = '$username'";
    	$result = mysql_query($query) or die("Query failed : " . mysql_error());
    	$line = mysql_fetch_array($result);
    	if($line['username'])
    	{
    		if($password != $line['password'])
    		{
    			echo "Incorrect password for <font color=#660000>" . $line['username'] . "</font>.";
    			$_SESSION['username'] = "";
    			$_SESSION['password'] = "";
    			session_unset();
    			session_destroy();
    		?>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    
    
    
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    //-->
    </script>
    <body>
    		<form action="login.php" method="post">
    <input type="hidden" name="login" value="yes">
      <br>
      <table width="631" border="0" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF">
      <tr bgcolor="#33CCFF"> 
          <td width="623" bgcolor="#000000"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Client 
            Login</strong></font></td>
      </tr>
      <tr bgcolor="#33CCFF"> 
        <td bgcolor="#FFFFFF"><font size="2" face="Arial, Helvetica, sans-serif">Username: 
            <input name="username" type="text" id="username" size="23">
          &nbsp;&nbsp; Password: 
            <input name="password" type="password" id="password" size="23">
          &nbsp;&nbsp; 
          <input name="Log In" type="submit" id="Log In2" value="Log In">
          </font><font size="2" face="Arial, Helvetica, sans-serif">&nbsp; </font></td>
      </tr>
      <tr>
        <td width="center" align="center"><font size="1" color="#000066" face="Arial, Helvetica, sans-serif">Forgot 
          your password?</font><font size="1" color="#FF0000" face="Arial, Helvetica, sans-serif"> 
          <a href="forgot.php">Click Here</a></font></td>
      </tr>
    </table>
    </form>
    		<?
    		bottom();
    		die();
    		}
    	} else {
    			
    		echo "The username '<font color=#660000>$username</font>' was not found in clients.<br>Please contact us for a username.";
    		$_SESSION['username'] = "";
    		$_SESSION['password'] = "";
    		session_unset();
    		session_destroy();
    		?>
    		<form action="login.php" method="post">
    <input type="hidden" name="login" value="yes">
      <br>
      <table width="631" border="0" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF">
      <tr bgcolor="#33CCFF"> 
          <td width="623" bgcolor="#000000"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Client 
            Login</strong></font></td>
      </tr>
      <tr bgcolor="#33CCFF"> 
        <td bgcolor="#FFFFFF"><font size="2" face="Arial, Helvetica, sans-serif">Username: 
            <input name="username" type="text" id="username" size="23">
          &nbsp;&nbsp; Password: 
            <input name="password" type="password" id="password" size="23">
          &nbsp;&nbsp; 
          <input name="Log In" type="submit" id="Log In2" value="Log In">
          </font><font size="2" face="Arial, Helvetica, sans-serif">&nbsp; </font></td>
      </tr>
      <tr>
        <td width="center" align="center"><font size="1" color="#000066" face="Arial, Helvetica, sans-serif">Forgot 
          your password?</font><font size="1" color="#FF0000" face="Arial, Helvetica, sans-serif"> 
          <a href="forgot.php">Click Here</a></font></td>
      </tr>
    </table>
    </form>
    		<?
    		bottom();
    		die();
    	}
    	$_SESSION['username'] = $line['username'];
    	$_SESSION['password'] = $line['password'];
    	
    	
    	
    ?> 
    <div align="left">
      <table width="660" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="456"><img src="<? if($admin_subdomain=="no"){ echo "/user/images"; } ?>/couchsm.jpg" width="216" height="101"><br>        <div align="left"><strong><font color="#000000" face="Arial, Helvetica, sans-serif"><? echo $admin_company; ?>
            -
                  Client Lounge</font></strong><font color="#000000"><br>
              <strong><font size="2" face="Arial, Helvetica, sans-serif"><i><? echo $line['company_name']; if($line['company_name'] == "") { echo $line['first_name'] . " " . $line['last_name']; } ?></i></font></strong><font face="Arial, Helvetica, sans-serif"><font size="1" face="Arial, Helvetica, sans-serif">&nbsp;| <a style="color:black;" href="logout.php">Log
              Out</a> </font><br>
            </font></font></div>
          </td>
          <td width="204" align="right"><img src="images/logo.png" width="256" height="119"></td>
        </tr>
      </table>
      <br>
      <font color="#003399" size="2" face="Arial, Helvetica, sans-serif"><b>Hi <? echo $line['first_name']; ?>!
      | <a href="invoices.php" style="color:blue"><font size="3">View All Invoices</font></a></b></font><br>
        <br>
    <?
    	$today = date('Y-m-d');
    	$query2 = 'SELECT * FROM `client_invoices` WHERE 1 AND `date_due` < \'' . $today . '\'  AND `paid` = \'due\'  AND `username` = \'' . $username . '\' LIMIT 0, 30';
    	//echo $query2;
    	$result2 = mysql_query($query2) or die("Query failed : " . mysql_error());
    	$line2 = mysql_fetch_array($result2);
    	if($line2)
    	{
    	echo "<font face='Arial, Helvetica, sans-serif' color='red' size='2'>You have overdue invoices that have not been paid.</font><br><br>";
    	}
    ?>
    <?
    	$query2 = 'SELECT * FROM `client_list` WHERE 1 AND `username` = \'' . $username . '\'';
    	//echo $query2;
    	$result2 = mysql_query($query2) or die("Query failed : " . mysql_error());
    	$line2 = mysql_fetch_array($result2);
    	if($line2['note'])
    	{
    	echo "<font face='Arial, Helvetica, sans-serif' size='2' color='#003399'><b>You have a message:</b><br>" . str_replace("\n", "<br>", $line2['note']) . "</font><br><br>";
    	}
    ?>
    <?
    bottom();
    ?>
    </div>
    
    
    PHP:



    
    <?
    function top()
    {
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>BILLING SYSTEM !</title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
    </head>
    
    <body>
    <table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="27" height="26"><img src="images/t_left.gif" width="27" height="26"></td>
        <td height="26" align="center" background="images/t_bg.gif"><img src="images/t_bg.gif" width="1" height="26"></td>
        <td width="27" height="26"><img src="images/t_right.gif" width="27" height="26"></td>
      </tr>
      <tr>
        <td width="27" background="images/left.gif"><img src="images/left.gif" width="27" height="1"></td>
        <td>
    <?
    }
    function bottom()
    {
    ?>
    </td>
        <td width="27" background="images/right.gif"><img src="images/right.gif" width="27" height="1"></td>
      </tr>
      <tr>
        <td width="27" height="26"><img src="images/b_left.gif" width="27" height="26"></td>
        <td height="26" align="center" background="images/b_bg.gif"><img src="images/b_bg.gif" width="1" height="26"></td>
        <td width="27" height="26"><img src="images/b_right.gif" width="27" height="26"></td>
      </tr>
    </table>
    </body>
    </html>
    <?
    }
    
    include("key.inc");
    function loginbox()
    {
    ?>
      <br>
      <table width="631" border="0" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF">
      <tr bgcolor="#000000"> 
          <td width="623"><font color="#ffffff" size="2" face="Arial, Helvetica, sans-serif"><strong>Client/Admin 
            Login</strong></font></td>
      </tr>
      <tr bgcolor="#33CCFF"> 
        <td bgcolor="#FFFFFF"><form action="login.php" method="post">
    <input type="hidden" name="login" value="yes"><font size="2" face="Arial, Helvetica, sans-serif">Username: 
            <input name="username" type="text" id="username" size="23">
          &nbsp;&nbsp; Password: 
            <input name="password" type="password" id="password" size="23">
          &nbsp;&nbsp; 
          <input name="Log In" type="submit" value="Log In"></form>
          </font><font size="2" face="Arial, Helvetica, sans-serif">&nbsp; </font></td>
      </tr>
      <tr>
        <td width="center" align="center"><font size="1" color="#000066" face="Arial, Helvetica, sans-serif">Forgot 
          your password?</font><font size="1" color="#FF0000" face="Arial, Helvetica, sans-serif"> 
          <a href="forgot.php">Click Here</a></font></td>
      </tr>
    </table>
    
    <?
    }
    include("admininc.php");
    ?>
    
    PHP:









    How can I fix this problem?
     
    mahacan, Oct 18, 2008 IP
  2. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    is there a space in front of the php tag?
     
    Kyosys, Oct 18, 2008 IP
  3. mahacan

    mahacan Banned

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3


    before <? tag?
    no there is no space.
     
    mahacan, Oct 18, 2008 IP
  4. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Warning: session_start() [function.session-start.php]: Cannot send session cache limiter - headers already sent (output started at D:\mydomain.com\wwwroot\user\login.php:1) in D:\mydomain.com\wwwroot\user\login.php on line 1

    This warning is basically saying that there has been some data sent already in line 1 of login.php, so the usual suspect is something that is not inside php tags. The other one is saying the same thing, so there has to be something that is being sent, usually a space or a letter somebody put accidentally. When I run the code pasted above, i do not get this error. Make sure there is no output before the script. Maybe a <html> or something, anything you didn't paste
     
    Kyosys, Oct 18, 2008 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    at your login.php

    <?php
    ob_start();
    session_start();
    include("functions.php");
    if($login == 'yes')
    {
    ...continue with your script
    
    PHP:
     
    ads2help, Oct 18, 2008 IP
  6. jgarrison

    jgarrison Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    At the very top of login.php:
    <?
    session_start();

    Immediately after <? hit return. Make sure session_start(); begins on the next line all the way to the left - no space before it.

    -Jim
     
    jgarrison, Oct 18, 2008 IP
  7. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That would do absolutely nothing to fix it. In fact, that would generally do absolutely nothing, except make the code prettier
     
    Kyosys, Oct 19, 2008 IP
  8. mahacan

    mahacan Banned

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hey I just did that but it didn't help.
     
    mahacan, Oct 19, 2008 IP
  9. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #9
    obviously it didn't. The output is being started on line one, that's the problem. starting an output buffer on line two does nothing to fix that. Are you sure there is NOTHING in front of the php tag, this is how the file starts?
     
    Kyosys, Oct 19, 2008 IP
  10. mahacan

    mahacan Banned

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    hi Jim
    I also tried this before.
     
    mahacan, Oct 19, 2008 IP
  11. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #11
    is your login.php file the main file? or is it only included in your page?
     
    serialCoder, Oct 19, 2008 IP
  12. linkexchange1984

    linkexchange1984 Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    generally this type of errors occur at the time not placing session_start(); function at the first line of the entire script..............



    ------------------------------
    Download FREE Ebooks
     
    linkexchange1984, Oct 19, 2008 IP
  13. Bind

    Bind Peon

    Messages:
    70
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #13
    that error means there are cookies/sessions already set, whitespace, or html output ocurring previously in the script execution.

    it might help to zip up all the files used in the script execution just as they are on your server so we can try to replicate the error.
     
    Bind, Oct 19, 2008 IP
  14. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #14
    no, all we need to know is if login is included somewhere. If it is, which it probably is, there must be output being made in that file, so they need to turn on output buffering in there
     
    Kyosys, Oct 19, 2008 IP
  15. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #15
    Just put ob_start() at the most top file =.=

    example, if your index.php looks like
    
    <?php
    scriptsssssssssss......
    scriptsssssssssss......
    include('login.php');
    
    PHP:
    then you should put ob_start() at your index.php

    if your index.php looks like
    
    <?php
    include('header.php');
    scriptsssssssssss......
    scriptsssssssssss......
    include('login.php');
    
    PHP:
    then you should put ob_start() at your header.php

    u get me? put ob_start() before any content even whitespace =.=
     
    ads2help, Oct 19, 2008 IP
  16. jgarrison

    jgarrison Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    I was trying to ensure that there wasn't a space character before the session start command.
     
    jgarrison, Oct 19, 2008 IP
  17. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #17
    but there can be a space character in front of the session start command, just not outside the php tags
     
    Kyosys, Oct 19, 2008 IP
  18. mahacan

    mahacan Banned

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Guys thank you for all... I did all stuff... I've contacted with my hosting company and support desk just told me that he just re-saved the file and resolved the problem.... After than I tried something.

    I've downloaded login.php file, just re-saved with my editor which is ms share point 2007, and uploaded to host again and get same error. After than I simply uploaded the back up file, error just gone...

    I did same process with dreamweaver. This time I didn't notice any error. So what I come up is editing file with sharepoint makes something that php gets error. There is no difference with the code just resaveing with sharepoint software is enough... very interesting... I should edit php files with dreamweaver...
     
    mahacan, Oct 20, 2008 IP
  19. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #19
    what format did you try saving in? UTF-8? ANSI?
     
    szalinski, Oct 21, 2008 IP
  20. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #20
    maybe there was a carriage return in front of the tag or something
     
    Kyosys, Oct 22, 2008 IP