944,100 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 33378
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 21st, 2006
0

session_start(): Cannot send session cookie - headers already sent by

Expand Post »
hi
thrr is no one who can help me this is the prog which when i run faces problem of session.

session_start(): Cannot send session cookie - headers already sent

pls plssssssssss help me to solve the problem below is the code

any one this is simple prog but i can't run
if i can't run thn my boss will kick me out of the office.
so pls hlp me.




[php]<?session_start();?>
<?php
include"db_config.php";
$connect = mysql_connect("$db_host", "$db_user", "$db_password");
mysql_select_db("$db_name", $connect) or die(mysql_error());
$f_name= $_POST['fname'];
$l_name= $_POST['lname'];
$pass= $_POST['password'];
$query = "SELECT * from helpagent WHERE first='$f_name' and last='$l_name' and password='$pass' ";
$result = mysql_query($query);
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$id = mysql_result($result, $i, "agentid");
$fname = mysql_result($result, $i, "first");
$lname = mysql_result($result, $i, "last");
$pas = mysql_result($result, $i, "password");
if (("$f_name" == "$fname") and ("$l_name" == "$lname") and ("$pass" == "$pas"))
{
$_SESSION['sfname'] = $fname;
$_SESSION['slname'] = $lname;
$_SESSION['sid'] = $id;
echo("<script>document.location.href='user_page.php';</script>");
exit;
}//if loop
}//for loop
?>[/php]
Last edited by cscgal; Jun 30th, 2006 at 7:42 pm.
Similar Threads
Reputation Points: 21
Solved Threads: 1
Newbie Poster
manish812 is offline Offline
12 posts
since Jun 2006
Jun 21st, 2006
0

Re: session_start(): Cannot send session cookie - headers already sent by

I suggest you read the other threads you started, as well as the manual. There are also some very good how-tos out there to teach you how to properly do what you want to.
Reputation Points: 23
Solved Threads: 23
Posting Pro in Training
Puckdropper is offline Offline
494 posts
since Jul 2004
Jun 29th, 2006
0

Re: session_start(): Cannot send session cookie - headers already sent by

Check the manual... if that script is included check that the file that it is actually including it doesn't have any print or echo. session_start() should be at the very beginning of the code.

Also change this:

[php]
<?session_start();?>
<?php
include"db_config.php";
[/php]

to this

[php]
<?php
session_start();
include"db_config.php";
[/php]

There is no need to break the PHP tags there... and use <?php also instead of <? it will make the script work in other servers. Or maybe your server doesn;t support short php tags.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
RamiroS is offline Offline
57 posts
since Mar 2005
Jul 1st, 2006
0

Re: session_start(): Cannot send session cookie - headers already sent by

I'm assuming that your including this file into another file, and in that other file you have already echoed something when this file is included.

Otherwise I cannot see what is wrong, as suggested the manual always helps.
Reputation Points: 10
Solved Threads: 1
Light Poster
BlazingWolf is offline Offline
32 posts
since Feb 2006
Oct 26th, 2009
-1
Re: session_start(): Cannot send session cookie - headers already sent by
Be sure that your SafeMode CLOSED. Ask your hosting company t switch it to CLOSED. The problem will be solved

Click to Expand / Collapse  Quote originally posted by manish812 ...
hi
thrr is no one who can help me this is the prog which when i run faces problem of session.

session_start(): Cannot send session cookie - headers already sent

pls plssssssssss help me to solve the problem below is the code

any one this is simple prog but i can't run
if i can't run thn my boss will kick me out of the office.
so pls hlp me.




[php]<?session_start();?>
<?php
include"db_config.php";
$connect = mysql_connect("$db_host", "$db_user", "$db_password");
mysql_select_db("$db_name", $connect) or die(mysql_error());
$f_name= $_POST['fname'];
$l_name= $_POST['lname'];
$pass= $_POST['password'];
$query = "SELECT * from helpagent WHERE first='$f_name' and last='$l_name' and password='$pass' ";
$result = mysql_query($query);
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$id = mysql_result($result, $i, "agentid");
$fname = mysql_result($result, $i, "first");
$lname = mysql_result($result, $i, "last");
$pas = mysql_result($result, $i, "password");
if (("$f_name" == "$fname") and ("$l_name" == "$lname") and ("$pass" == "$pas"))
{
$_SESSION['sfname'] = $fname;
$_SESSION['slname'] = $lname;
$_SESSION['sid'] = $id;
echo("<script>document.location.href='user_page.php';</script>");
exit;
}//if loop
}//for loop
?>[/php]
Reputation Points: 9
Solved Threads: 0
Newbie Poster
berhansoner is offline Offline
1 posts
since Oct 2009
Oct 27th, 2009
0
Re: session_start(): Cannot send session cookie - headers already sent by
PHP Syntax (Toggle Plain Text)
  1. <?php session_start();
  2. ob_start();
  3.  
  4. include"db_config.php";
  5.  
  6. $connect = mysql_connect("$db_host", "$db_user", "$db_password");
  7. mysql_select_db("$db_name", $connect) or die(mysql_error());
  8. $f_name= $_POST['fname'];
  9. $l_name= $_POST['lname'];
  10. $pass= $_POST['password'];
  11. $query = "SELECT * from helpagent WHERE first='$f_name' and last='$l_name' and password='$pass' ";
  12. $result = mysql_query($query);
  13. for ($i = 0; $i < mysql_num_rows($result); $i++)
  14. {
  15. $id = mysql_result($result, $i, "agentid");
  16. $fname = mysql_result($result, $i, "first");
  17. $lname = mysql_result($result, $i, "last");
  18. $pas = mysql_result($result, $i, "password");
  19. if (("$f_name" == "$fname") and ("$l_name" == "$lname") and ("$pass" == "$pas"))
  20. {
  21. $_SESSION['sfname'] = $fname;
  22. $_SESSION['slname'] = $lname;
  23. $_SESSION['sid'] = $id;
  24. echo("<script>document.location.href='user_page.php';</script>");
  25. exit;
  26. }//if loop
  27. }//for loop
  28. ?>
Reputation Points: 10
Solved Threads: 3
Newbie Poster
alagirinetaxis is offline Offline
15 posts
since Oct 2009
Nov 30th, 2009
0
Re: session_start(): Cannot send session cookie - headers already sent by
Sometimes the problem is caused by the Dreamweaver's "Include Unicode Signature (BOM)" property.
To turn it off go to Modify > Page Properties > Title/Encoding in Dreamweaver and uncheck "Include Unicode Signature (BOM)"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
toddor is offline Offline
1 posts
since Nov 2009
Mar 28th, 2010
0

I am happy

I had the same problem and solved it. do you know how? use error suppression operator @ symbol just before session_start().
i. e., <?php
ob_start();
@session_start();
?>
It really works without any problem :-)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sahana_prasanna is offline Offline
1 posts
since Oct 2009
Mar 28th, 2010
0
Re: session_start(): Cannot send session cookie - headers already sent by
If your going to use the ob_start() tag dont forget the ob_flush() tag right at the end of the page.
But obviously its better if you can actually sort the problem out.
Reputation Points: 10
Solved Threads: 1
Light Poster
daryll1 is offline Offline
41 posts
since Nov 2009
Aug 31st, 2010
0

I hade the same problem, and i solve it

I hade the same problem, and i solve it with Toddors replay (Sometimes the problem is caused by the Dreamweaver's
Thank you Toddor.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
66geo is offline Offline
1 posts
since Aug 2010
Message:
Previous Thread in PHP Forum Timeline: Session destroy not working....
Next Thread in PHP Forum Timeline: PDF format, using php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC