session_start() causing "Cannot send session cache limiter."

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
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

session_start() causing "Cannot send session cache limiter."

Post by morris520 »

Hi

Can you help me on this problem?

I am doing two pages, when user click "account" button on display.php then go to edit.php with account details but when I try to add session_start() on top of edit, it bumps error message as title:

please give me a hand, thanks

Sorry I think a whole document will be better to read so I post it all.

display.php

Code: Select all

 
 
<?php
 
    include 'conn.php';
    include 'define.php';
 
    session_start();
    check_session_fail();
 
 
    $sqlQuery1 = "select * from customer";
 
    //?????
    $selectR = mysql_db_query($dbname, $selectSQL, $connect);
    if( !$selectR ){
        echo " select fails !";
    }
 
 
    $add = "redirect('add.php')";
    $edit = "redirect('edit.php?id=".$_SESSION['id']."')";
    $logout = "redirect('login/logout.php')";
    $clear = "redirect('clear.php')";
    
?>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style/global.css">
<script src="script.js"></script>
</head>
 
<body>
<center>
    <table class="table1">
        <tr>
            <td align="center">
                Display
            </td>
        </tr>
        <tr>
            <td align="center">
                <img src="img/top.jpg">
            </td>
        </tr>
        <!-- Greeting Message -->
        <tr>
            <td align="center">
                Hello, <?php echo $_SESSION['myusername'];?> you are logged in.
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="Add" onclick=<?php echo $add;?>>
                <input type="button" value="Account" onclick=<?php echo $edit;?>>
                <input type="button" value="Search">
                <input type="button" value="Clear" onclick=<?php echo $clear;?>>
                <input type="button" value="Logout" onclick=<?php echo $logout;?>>
            </td>
        </tr>
        <tr>
            <td align="center">
                <hr width="100%">               
            </td>
        </tr>
        <tr>
            <td align="center">
                Database        
            </td>
        </tr>
 
        <?php
            while($row = mysql_fetch_array($selectR, MYSQL_ASSOC))
            {
        ?>
        <tr>
            <td>
                <hr>
            </td>
        </tr>
        <tr>
            <td align="center">
                <table class="table2" width="220">
                    <tr>
                        <td width="120">
                            ID              
                        </td>
                        <td>
                            <?php echo $row['id'];?>                
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Username                
                        </td>
                        <td>
                            <?php echo $row['username'];?>              
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Address             
                        </td>
                        <td>
                            <?php echo $row['address'];?>               
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Contact             
                        </td>
                        <td>
                            <?php echo $row['contact'];?>               
                        </td>
                    </tr>
                    <tr height="20">
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center">
                            <input name="Input" type="button" value="Edit">
                            <input name="Input" type="button" value="Delete">
                        </td>
                    </tr>
              </table>
            </td>
        </tr>
        <?php
            }
        ?>
        <tr height="25">        
            <td><hr></td>
        </tr>
 
    </table>    
</center>
</body>
</html>
 
 
 
edit.php

Code: Select all

 
 
<?php
 
    include 'conn.php';
    include 'define.php';
 
    session_start();
    check_session_fail();
 
    $id = $_REQUEST['id'];
    $result = $_REQUEST['result'];
 
    //echo "id=".$id;
 
    $selectSQL = "select * from customer where id = ".$id;
 
    $selectR = mysql_db_query($dbname, $selectSQL, $connect);
 
    if( !$selectR ){
        echo " select fails !";
    }
 
?>
 
 
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Edit</title>
<link rel="stylesheet" type="text/css" href="style/global.css">
<script src="script.js"></script>
</head>
 
<body>
 
<center>
    <form action="edit_proc.php">
        <table class="table1">
            <tr>
                <td align="center">
                    Edit
                </td>
            </tr>
            <tr>
                <td align="center">
                    <img src="img/top.jpg">
                </td>
            </tr>
            <tr>
                <td align="center">
                    <hr width="100%">               
                </td>
            </tr>
            
            <?php
            while($row = mysql_fetch_array($selectR, MYSQL_ASSOC))
            {    
            ?>                                   
            <tr>
                <td align="center">
                    Details:    <?php echo $row['username'];?>  
                </td>
            </tr>
            <tr>
                <td align="center">
                    <hr width="100%">               
                </td>
            </tr>
 
                        <tr>
                        <td>
                            <table>
                            <tr><td><input type="hidden" name="id" value=<?php echo $row['id'];?>></td></tr>
                            <tr>
                                <td width='10%'>Username</td>
                                <td width='20%'><input type="text" name="username" value=<?php echo $row['username'];?>></td>       
                            </tr>   
                            <!-- ?? -->
                            <!-- <tr>
                                <td width='10%'>Password</td>
                                <td width='20%'><input type="text" name="password"></td>        
                            </tr>    -->
                            <tr>
                                <td width='10%'>Address</td>
                                <td width='20%'><input type="text" name="address" value=<?php echo $row['address'];?>></td>                         
                            </tr>   
                            <tr>
                                <td width='10%'>Contact</td>
                                <td width='20%'><input type="text" name="contact" value=<?php echo $row['contact'];?>></td>                         
                            </tr>   
                            </table>
                        </td>
                        </tr>
                <?php       
                } 
                ?>
 
                <tr>
                    <td align="center">
                        <hr width="100%">               
                    </td>
                </tr>
                <tr>
                    <td align="center">
                        <input type="submit" value="Edit">
                        <input type="reset" value="Reset">
                        <input type="button" value="Back" onclick="redirect('display.php')">
                        <input type="button" value="Password" onclick="redirect('password.php')">
                    </td>
                </tr>
                <tr>
                    <td align="center">
                        <hr width="100%">               
                    </td>
                </tr>
                <tr>
                    <td align="center">
                        <?php 
                            if(!empty($result)){
                                if($result==1){
                        ?>
                        The record has been successfully edited.
                        <?php                           
                                }
                                else{
                        ?>
                        The record is incorrect!
                        <?php
                                }
                            }
                        ?>
                    </td>
                </tr>
        </table>
    </form>
</center>
 
</body>
 
 
 
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: session_start() causing "Cannot send session cache limiter."

Post by Ziq »

If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.

Post the full error message.
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: session_start() causing "Cannot send session cache limiter."

Post by morris520 »

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\m\consign\edit.php:2) in C:\Program Files\Apache Group\Apache2\htdocs\m\consign\edit.php on line 7
id=11

This is full error
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: session_start() causing "Cannot send session cache limiter."

Post by pickle »

Remember that the parts of a PHP file that aren't inside PHP tags are sent to the browser as (usually) HTML.

Code: Select all

    <-- //Even though there's no code here, it still gets sent to the browser as a blank line
<?PHP
 
/* random PHP code */
 
?>
 
Please search the forums before posting. This issue has been previous encountered and answered.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: session_start() causing "Cannot send session cache limiter."

Post by morris520 »

pickle :

Yeah this is the point.

I didn't put <?php in the first line so the server treats it as a blank
now I fix it! thanks
Post Reply