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.

<?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
?>

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.

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:

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

to this

<?php
session_start();
include"db_config.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.

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.

Be sure that your SafeMode CLOSED. Ask your hosting company t switch it to CLOSED. The problem will be solved

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.

<?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
?>
commented: DONT BUMP 3 YEAR OLD THREADS. -1
<?php session_start();
ob_start();

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
?>

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)"

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 :-)

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.

I hade the same problem, and i solve it with Toddors replay (Sometimes the problem is caused by the Dreamweaver's
Thank you Toddor.

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 :-)

Great solution... tried it and it worked perfectly. Thanks for the help

thanks...sahana prasanna....you are right its works

it's worked but, click to another page the page back to login page. The session () not working.