473,396 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

127 100+
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
14 3050
Motoma
3,237 Expert 2GB
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
bb nicole
127 100+
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
3,237 Expert 2GB
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
bb nicole
127 100+
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
bb nicole
127 100+
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
bb nicole
127 100+
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
3,237 Expert 2GB
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
bb nicole
127 100+
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
3,237 Expert 2GB
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
bb nicole
127 100+
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
3,237 Expert 2GB
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
bb nicole
127 100+
Emm... I know, but i don't know how to edit the code...
So, what should i do now??
Thanks..
Feb 4 '07 #13
bb nicole
127 100+
Did anyone have idea how to do it?? I really out of idea... Thanks...
Feb 4 '07 #14
bb nicole
127 100+
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

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

Similar topics

2
by: mr_burns | last post by:
Hi, i am getting the following errors when running my php script: Warning: Cannot send session cookie - headers already sent by (output started at ...
4
by: Bob | last post by:
Seem to have a problem ending a session. I get the following message. Warning: session_start(): Cannot send session cookie - headers already sent by (output started at...
3
by: lawrence k | last post by:
I'm getting this warning: PHP Warning: session_start(): Cannot send session cache limiter - headers already sent in...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
1
by: juergen | last post by:
Hi, there are many postings on this subject, I have read them put don't have an answer. I get these warnings: Cannot send session cookie - headers already sent in, but my php-scripts are okay. ...
4
by: three-eight-hotel | last post by:
I'm somewhat of a newbie to PHP coding, but have developed a site using the technology, and have been pleasantly surprised by the capabilities offered. I am more comfortable in the ASP world,...
1
by: gipsy | last post by:
Hello, I know that you guys are familiar with this, but I tried almost every solution I googled, but no chance getting it wroked, here is the error. and here is the sessiondata.php lines,...
11
by: craigtomo | last post by:
i have changed my login .php file to the following this file is opened directly and is not called from any other file <?php // dBase file $host=""; // Host name $username=""; // Mysql...
3
by: tedpottel | last post by:
Hi I cannot get sessions to work. I have the following code </body> <? session_start(); $counter++; print "You have visited this page $counter times during this session";...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.