Cannot send session cookie?? Cannot send session cache limiter??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bb nicole
    New Member
    • Jan 2007
    • 127

    Cannot send session cookie?? Cannot send session cache limiter??

    I using session when creaate a forum. But it display error like:
    Warning: session_start() : Cannot send session cookie - headers already sent by (output started at C:\Apache2\Apac he2\htdocs\foru mReply_act.php: 9) in C:\Apache2\Apac he2\htdocs\foru mReply_act.php on line 11

    Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at C:\Apache2\Apac he2\htdocs\foru mReply_act.php: 9) in C:\Apache2\Apac he2\htdocs\foru mReply_act.php on line 11
    Your reply has being posted!
    Other than that it can function well, what is the problem?? Thanks..

    The code something like below:
    [PHP]
    <?php
    ob_start();
    session_start() ;
    //create and issue the first query
    $add_topic = "insert into forumtopic values ('', '$_POST[title]', '$_SESSION[username]', now(), '$_POST[comment]')";
    mysql_query($ad d_topic,$conn) or die(mysql_error ());
    ?>[/PHP]
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by bb nicole
    I using session when creaate a forum. But it display error like:
    Warning: session_start() : Cannot send session cookie - headers already sent by (output started at C:\Apache2\Apac he2\htdocs\foru mReply_act.php: 9) in C:\Apache2\Apac he2\htdocs\foru mReply_act.php on line 11

    Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at C:\Apache2\Apac he2\htdocs\foru mReply_act.php: 9) in C:\Apache2\Apac he2\htdocs\foru mReply_act.php on line 11
    Your reply has being posted!
    Other than that it can function well, what is the problem?? Thanks..

    The code something like below:
    [PHP]
    <?php
    ob_start();
    session_start() ;
    //create and issue the first query
    $add_topic = "insert into forumtopic values ('', '$_POST[title]', '$_SESSION[username]', now(), '$_POST[comment]')";
    mysql_query($ad d_topic,$conn) or die(mysql_error ());
    ?>[/PHP]
    It doesn't look like you posted the correct file...
    The error says you are trying to send a Header after you have already sent data to the page. This is a no-no.

    Comment

    • bb nicole
      New Member
      • Jan 2007
      • 127

      #3
      emm.. sorry.. what do you mean?? The error said header already sent on line 11, my php code in line 11 is session_start() ;
      But when i delete the session on line 11, i can't get user name in my page??
      So, what should i do??

      [PHP]<?php
      ob_start();
      session_start() ;
      //check for required fields from the form
      if ((!$_POST[title])
      || (!$_POST[comment])) {
      header ("Location: forumAdd.php");
      exit;
      }



      //connect to server and select database
      $conn = mysql_connect(" localhost", "root", "")
      or die (mysql_error()) ;
      mysql_select_db ("ums e-job portal",$conn) or die(mysql_error ());

      //create and issue the first query
      $add_topic = "insert into forumtopic values ('', '$_POST[title]', '$_SESSION[username]', now(), '$_POST[comment]')";
      mysql_query($ad d_topic,$conn) or die(mysql_error ());

      //get the id of the last query
      $ID = mysql_insert_id ();


      //create messege for user indicate bulletin adding success

      $msg = ("Your Forum titled $_POST[title] has being created");

      ?>
      <? echo $msg; ?>
      <? include("forum. php");
      ?>[/PHP]

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by bb nicole
        emm.. sorry.. what do you mean?? The error said header already sent on line 11, my php code in line 11 is session_start() ;
        But when i delete the session on line 11, i can't get user name in my page??
        So, what should i do??

        [PHP]<?php
        ob_start();
        session_start() ;
        //check for required fields from the form
        if ((!$_POST[title])
        || (!$_POST[comment])) {
        header ("Location: forumAdd.php");
        exit;
        }



        //connect to server and select database
        $conn = mysql_connect(" localhost", "root", "")
        or die (mysql_error()) ;
        mysql_select_db ("ums e-job portal",$conn) or die(mysql_error ());

        //create and issue the first query
        $add_topic = "insert into forumtopic values ('', '$_POST[title]', '$_SESSION[username]', now(), '$_POST[comment]')";
        mysql_query($ad d_topic,$conn) or die(mysql_error ());

        //get the id of the last query
        $ID = mysql_insert_id ();


        //create messege for user indicate bulletin adding success

        $msg = ("Your Forum titled $_POST[title] has being created");

        ?>
        <? echo $msg; ?>
        <? include("forum. php");
        ?>[/PHP]
        Sorry, my mistake. I misread the error.
        Is this the only content on the page? If so, then try putting session_start() before ob_start().

        Comment

        • bb nicole
          New Member
          • Jan 2007
          • 127

          #5
          Emm... Sorry.. I got 6 pages on my php coding for forum... The code i display on forum is just one of the 6 pages(name:foru mAdd_act.php). Below is my other page of coding...

          forum.php
          [PHP]<?php
          //connect to server and select database
          $conn = mysql_connect(" localhost", "root", "")
          or die (mysql_error()) ;
          mysql_select_db ("ums e-job portal",$conn) or die(mysql_error ());


          //gather the topics
          $get_topics = "select forumID, forumTopic,
          date_format(for umTime, '%b %e %Y at %r') as fmt_forumTime,
          forumComment from forumtopic order by forumTime desc";
          $get_topic_res = mysql_query($ge t_topics,$conn) or die(mysql_error ());

          $num=mysql_num_ rows($get_topic _res);

          $numusers=mysql _query($get_top ics) or die ("Select Failed - count");
          $numuser=mysql_ fetch_array($nu musers);
          ?>
          <?

          $queryc="SELECT * FROM forumtopic ORDER BY forumID";

          $userlist=mysql _query($queryc) or die("Cannot connect to server");

          ?>
          <h1 align="center"> <font face="Arial, Helvetica, sans-serif">UMS Career Forum</font></h1>
          <p align="center"> <a href="forumAdd. php"><font face="Arial, Helvetica, sans-serif">New Topic => Start discussion</font></a></p>
          <center>
          </font>
          <table border=1 cellpadding=3 cellspacing=1 bgcolor="#00000 0" >
          <tr bgcolor="#00000 0">
          <th width="450"><fo nt face="Arial, Helvetica, sans-serif"><span class="style3"> TOPICS</span></font></th>
          <th width="150"><fo nt face="Arial, Helvetica, sans-serif"><span class="style3"> AUTHOR</span></font></th>
          <th width="150"><fo nt face="Arial, Helvetica, sans-serif"><span class="style3"> LAST POST</span></font></th>
          </tr>
          Total Forum Topics : <? echo $num; ?>
          <?
          while ($userinfo = mysql_fetch_arr ay($userlist)){
          ?>
          <tr >
          <td width="450"> <font face="Arial, Helvetica, sans-serif"><strong> <a href="forumTopi c.php?forumID=< ? echo $userinfo['forumID'];?>"><? echo $userinfo['forumTopic'];?>
          </a></strong>
          <p><? echo $userinfo['forumComment']; ?></p>
          </font></td>
          <td align="center" width="150"><fo nt face="Arial, Helvetica, sans-serif"><? echo $userinfo['username']; ?>
          </font></td>
          <td align="center" width="150"><fo nt face="Arial, Helvetica, sans-serif"><? echo $userinfo['forumTime']; ?></font></td>
          </tr>
          <? } ?>[/PHP]


          forumAdd.php
          [HTML]<form method=post action="forumAd d_act.php">
          <p align="center">

          <p align="center"> <strong><font face="Arial, Helvetica, sans-serif">Forum Title:</font></strong><br/>
          <input type="text" name="title" size="40" maxlength="150" >

          <p align="center"> <strong><font face="Arial, Helvetica, sans-serif">Comment: </font></strong><br/>
          <textarea name="comment" rows="8" cols="40" wrap=virtual></textarea>
          <p>
          <center><inpu t type="submit" name="submit" value="Submit">
          </center>
          </p>
          </form>
          [/HTML]

          Comment

          • bb nicole
            New Member
            • Jan 2007
            • 127

            #6
            forumReply.php
            [PHP]<?php
            $_GET[forumID];

            $conn = mysql_connect(" localhost", "root", "")
            or die (mysql_error()) ;
            mysql_select_db ("ums e-job portal",$conn) or die ("Cannot connect");

            //verity the topic exists
            $verify_topic = "select * from forumtopic where
            forumID = '$_GET[forumID]'";
            $verify_topic_r es = mysql_query($ve rify_topic, $conn)
            or die ("Cannot connect to server");
            while ($forumIS = mysql_fetch_arr ay($verify_topi c_res)){

            ?>

            <h2 align="center"> Reply to <? echo $forumIS['forumTopic']; ?> </h2>
            <? } ?>[/PHP]
            [HTML]<form method=post action="forumRe ply_act.php?for umID=<? echo $_GET[forumID];?>">
            <p align="center">
            <p align="center"> <br/>
            <p align="center"> <strong>Reply :</strong><br/>
            <textarea name="reply" rows="8" cols="40" wrap=virtual></textarea>
            <p>
            <center><inpu t type="submit" name="submit" value="Reply">
            </center>
            </p>
            </form>[/HTML]

            forumReply_act. php
            [PHP]<?php
            ob_start();
            session_start() ;
            //check for required fields from the form
            $_GET[forumID];


            //connect to server and select database
            $conn = mysql_connect(" localhost", "root", "")
            or die (mysql_error()) ;
            mysql_select_db ("ums e-job portal",$conn) or die(mysql_error ());

            //create and issue the first query
            $add_topic = "insert into forumpost values ('', '$_GET[forumID]', '$_SESSION[username]', now(), '$_POST[reply]')";
            mysql_query($ad d_topic,$conn) or die(mysql_error ());

            //get the id of the last query
            $ID = mysql_insert_id ();


            //create messege for user indicate bulletin adding success

            $msg = ("Your reply has being posted!");

            ?>

            <? echo $msg; ?>

            <? include("forum. php")
            ?>[/PHP]

            forumTopic.php
            [PHP]<?php
            //check for required info from the query string
            $_GET[forumID];

            $conn = mysql_connect(" localhost", "root", "")
            or die (mysql_error()) ;
            mysql_select_db ("ums e-job portal",$conn) or die ("Cannot connect");

            //verity the topic exists
            $verify_topic = "select * from forumtopic where
            forumID = '$_GET[forumID]'";
            $verify_topic_r es = mysql_query($ve rify_topic, $conn)
            or die ("Cannot connect to server");
            ?>
            <?
            while ($forumIS = mysql_fetch_arr ay($verify_topi c_res)){

            ?>

            <h2><font face="Arial, Helvetica, sans-serif">Forum title : <? echo $forumIS['forumTopic']; ?></font></h2>
            <p><font face="Arial, Helvetica, sans-serif">By : </font><? echo $forumIS['username']; ?><br>
            <font face="Arial, Helvetica, sans-serif">On :</font> <? echo $forumIS['forumTime']; ?></p>
            <p><font face="Arial, Helvetica, sans-serif">Comment :</font><br>
            <? echo $forumIS['forumComment']; ?></p>
            <? } ?>

            <p><a href="forumRepl y.php?forumID=< ? echo $_GET[forumID];?>"><font face="Arial, Helvetica, sans-serif">Reply
            a Post</font></a></p>
            <?

            $get_totalPosts = "select * from forumpost where forumID = '$_GET[forumID]' ORDER BY postID desc";

            $get_totalPosts _res = mysql_query($ge t_totalPosts,$c onn) or die (mysql_error()) ;

            $num=mysql_num_ rows($get_total Posts_res);

            $get_posts = "select * from forumpost where forumID = '$_GET[forumID]' ORDER BY postID desc";

            $get_posts_res = mysql_query($ge t_posts,$conn) or die (mysql_error()) ;

            ?>
            <font face="Arial, Helvetica, sans-serif"> Total reply(s) :</font> <? echo $num;?><br>
            <br>
            <table border="1"><tr>
            <td width="400"><st rong><font face="Arial, Helvetica, sans-serif">Reply</font></strong></td>
            <td width="50"><fon t face="Arial, Helvetica, sans-serif">By</font></td>
            <td width="50"><fon t face="Arial, Helvetica, sans-serif">On</font></td>
            </tr>

            <?
            while ($posts_info = mysql_fetch_arr ay($get_posts_r es)) {
            ?>
            <tr>
            <td><? echo $posts_info['postContent'];?></td>
            <td><? echo $posts_info['username'];?></td>
            <td><? echo $posts_info['postTime'];?></td>
            </tr>
            <? } ?>
            [/PHP]

            Comment

            • bb nicole
              New Member
              • Jan 2007
              • 127

              #7
              Actually the forum can function, but it can not show the correct username of user when they take part in forum... Thus, i add:
              ob_start();
              session_start() ;
              and
              when insert into table values(''', '$_POST[title], '$_SESSION[username]', ....)

              I add session to the username in my coding...
              But now the problem is like i show before...
              It display:
              Warning: session_start() : Cannot send session cookie - headers already sent by (output started at C:\Apache2\Apac he2\htdocs\foru mReply_act.php: 9) in C:\Apache2\Apac he2\htdocs\foru mReply_act.php on line 11

              Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at C:\Apache2\Apac he2\htdocs\foru mReply_act.php: 9) in C:\Apache2\Apac he2\htdocs\foru mReply_act.php on line 11
              Your reply has being posted!

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                Originally posted by bb nicole
                Actually the forum can function, but it can not show the correct username of user when they take part in forum... Thus, i add:
                ob_start();
                session_start() ;
                and
                when insert into table values(''', '$_POST[title], '$_SESSION[username]', ....)

                I add session to the username in my coding...
                But now the problem is like i show before...
                It display:
                Warning: session_start() : Cannot send session cookie - headers already sent by (output started at C:\Apache2\Apac he2\htdocs\foru mReply_act.php: 9) in C:\Apache2\Apac he2\htdocs\foru mReply_act.php on line 11

                Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at C:\Apache2\Apac he2\htdocs\foru mReply_act.php: 9) in C:\Apache2\Apac he2\htdocs\foru mReply_act.php on line 11
                Your reply has being posted!
                Try putting session_start() before ob_start().

                Comment

                • bb nicole
                  New Member
                  • Jan 2007
                  • 127

                  #9
                  Originally posted by Motoma
                  Try putting session_start() before ob_start().

                  Is it like:
                  [PHP]<?php
                  session_start() ;
                  ob_start();
                  ?>
                  [/PHP]

                  It cannot work also, the error show hearder already sent on line 10... Line 10 is session_start() ;
                  The erroe display like below:
                  Warning: session_start() : Cannot send session cookie - headers already sent by (output started at C:\Apache2\Apac he2\htdocs\foru mReply_act.php: 9) in C:\Apache2\Apac he2\htdocs\foru mReply_act.php on line 10

                  Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at C:\Apache2\Apac he2\htdocs\foru mReply_act.php: 9) in C:\Apache2\Apac he2\htdocs\foru mReply_act.php on line 10
                  Your reply has being posted!


                  Thanks...:)

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    Do you get the errors if you don't use ob_start() at all? That is, remove it entirely from your script.

                    Comment

                    • bb nicole
                      New Member
                      • Jan 2007
                      • 127

                      #11
                      Originally posted by Motoma
                      Do you get the errors if you don't use ob_start() at all? That is, remove it entirely from your script.


                      Yes... When i remove it from my scripts, i don't get any error, but it can't display the username of the user when they post or reply in forum... It display a serial of string...

                      Comment

                      • Motoma
                        Recognized Expert Specialist
                        • Jan 2007
                        • 3236

                        #12
                        Originally posted by bb nicole
                        Yes... When i remove it from my scripts, i don't get any error, but it can't display the username of the user when they post or reply in forum... It display a serial of string...
                        Well then that is the reason why you are getting the error.
                        Not being able to see usernames is another problem all together.

                        Comment

                        • bb nicole
                          New Member
                          • Jan 2007
                          • 127

                          #13
                          Emm... I know, but i don't know how to edit the code...
                          So, what should i do now??
                          Thanks..

                          Comment

                          • bb nicole
                            New Member
                            • Jan 2007
                            • 127

                            #14
                            Did anyone have idea how to do it?? I really out of idea... Thanks...

                            Comment

                            • bb nicole
                              New Member
                              • Jan 2007
                              • 127

                              #15
                              Originally posted by Motoma
                              Well then that is the reason why you are getting the error.
                              Not being able to see usernames is another problem all together.

                              Do you have any idea what is the problem of the code??? Thanks, Motoma... :)

                              Comment

                              Working...