By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,047 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,047 IT Pros & Developers. It's quick & easy.

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

100+
P: 127
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\Apache2\htdocs\forumReply_act.php:9) in C:\Apache2\Apache2\htdocs\forumReply_act.php on line 11

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Apache2\Apache2\htdocs\forumReply_act.php:9) in C:\Apache2\Apache2\htdocs\forumReply_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($add_topic,$conn) or die(mysql_error());
?>[/PHP]
Feb 2 '07 #1
Share this Question
Share on Google+
14 Replies


Motoma
Expert 2.5K+
P: 3,235
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\Apache2\htdocs\forumReply_act.php:9) in C:\Apache2\Apache2\htdocs\forumReply_act.php on line 11

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Apache2\Apache2\htdocs\forumReply_act.php:9) in C:\Apache2\Apache2\htdocs\forumReply_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($add_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.
Feb 2 '07 #2

100+
P: 127
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($add_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]
Feb 2 '07 #3

Motoma
Expert 2.5K+
P: 3,235
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($add_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().
Feb 2 '07 #4

100+
P: 127
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:forumAdd_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(forumTime, '%b %e %Y at %r') as fmt_forumTime,
forumComment from forumtopic order by forumTime desc";
$get_topic_res = mysql_query($get_topics,$conn) or die(mysql_error());

$num=mysql_num_rows($get_topic_res);

$numusers=mysql_query($get_topics) or die ("Select Failed - count");
$numuser=mysql_fetch_array($numusers);
?>
<?

$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="#000000" >
<tr bgcolor="#000000">
<th width="450"><font face="Arial, Helvetica, sans-serif"><span class="style3">TOPICS</span></font></th>
<th width="150"><font face="Arial, Helvetica, sans-serif"><span class="style3">AUTHOR</span></font></th>
<th width="150"><font face="Arial, Helvetica, sans-serif"><span class="style3">LAST POST</span></font></th>
</tr>
Total Forum Topics : <? echo $num; ?>
<?
while ($userinfo = mysql_fetch_array($userlist)){
?>
<tr >
<td width="450"> <font face="Arial, Helvetica, sans-serif"><strong><a href="forumTopic.php?forumID=<? echo $userinfo['forumID'];?>"><? echo $userinfo['forumTopic'];?>
</a></strong>
<p><? echo $userinfo['forumComment']; ?></p>
</font></td>
<td align="center" width="150"><font face="Arial, Helvetica, sans-serif"><? echo $userinfo['username']; ?>
</font></td>
<td align="center" width="150"><font face="Arial, Helvetica, sans-serif"><? echo $userinfo['forumTime']; ?></font></td>
</tr>
<? } ?>[/PHP]


forumAdd.php
[HTML]<form method=post action="forumAdd_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><input type="submit" name="submit" value="Submit">
</center>
</p>
</form>
[/HTML]
Feb 2 '07 #5

100+
P: 127
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_res = mysql_query($verify_topic, $conn)
or die ("Cannot connect to server");
while ($forumIS = mysql_fetch_array($verify_topic_res)){

?>

<h2 align="center">Reply to <? echo $forumIS['forumTopic']; ?> </h2>
<? } ?>[/PHP]
[HTML]<form method=post action="forumReply_act.php?forumID=<? 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><input 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($add_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_res = mysql_query($verify_topic, $conn)
or die ("Cannot connect to server");
?>
<?
while ($forumIS = mysql_fetch_array($verify_topic_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="forumReply.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($get_totalPosts,$conn) or die (mysql_error());

$num=mysql_num_rows($get_totalPosts_res);

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

$get_posts_res = mysql_query($get_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"><strong><font face="Arial, Helvetica, sans-serif">Reply</font></strong></td>
<td width="50"><font face="Arial, Helvetica, sans-serif">By</font></td>
<td width="50"><font face="Arial, Helvetica, sans-serif">On</font></td>
</tr>

<?
while ($posts_info = mysql_fetch_array($get_posts_res)) {
?>
<tr>
<td><? echo $posts_info['postContent'];?></td>
<td><? echo $posts_info['username'];?></td>
<td><? echo $posts_info['postTime'];?></td>
</tr>
<? } ?>
[/PHP]
Feb 2 '07 #6

100+
P: 127
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\Apache2\htdocs\forumReply_act.php:9) in C:\Apache2\Apache2\htdocs\forumReply_act.php on line 11

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Apache2\Apache2\htdocs\forumReply_act.php:9) in C:\Apache2\Apache2\htdocs\forumReply_act.php on line 11
Your reply has being posted!
Feb 2 '07 #7

Motoma
Expert 2.5K+
P: 3,235
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\Apache2\htdocs\forumReply_act.php:9) in C:\Apache2\Apache2\htdocs\forumReply_act.php on line 11

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Apache2\Apache2\htdocs\forumReply_act.php:9) in C:\Apache2\Apache2\htdocs\forumReply_act.php on line 11
Your reply has being posted!
Try putting session_start() before ob_start().
Feb 2 '07 #8

100+
P: 127
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\Apache2\htdocs\forumReply_act.php:9) in C:\Apache2\Apache2\htdocs\forumReply_act.php on line 10

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


Thanks...:)
Feb 3 '07 #9

Motoma
Expert 2.5K+
P: 3,235
Do you get the errors if you don't use ob_start() at all? That is, remove it entirely from your script.
Feb 3 '07 #10

100+
P: 127
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...
Feb 3 '07 #11

Motoma
Expert 2.5K+
P: 3,235
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.
Feb 4 '07 #12

100+
P: 127
Emm... I know, but i don't know how to edit the code...
So, what should i do now??
Thanks..
Feb 4 '07 #13

100+
P: 127
Did anyone have idea how to do it?? I really out of idea... Thanks...
Feb 4 '07 #14

100+
P: 127
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... :)
Feb 5 '07 #15

Post your reply

Sign in to post your reply or Sign up for a free account.