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

i want to use session in my prog and this error comes every times due 2 which i cann't use session which is vry important for me.

but whn i run the same prog in my computer i.e. localhost it run correctly but when i load that file in the server than this error comes.

so pls help me to avoid this session error

my boss fire on me :sad: :sad: :sad: :sad: :sad: :sad: :sad: :sad:

pls pls help me

here is the my prog ----------------

<? ob_start();
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());
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0046)http://acmserver.cs.ucr.edu/~nkumar/vision.htm -->
<HTML>
<HEAD><TITLE>Bankon Us</TITLE>
<body topmargin="0" leftmargin="0">
<tr>
<TD align=center> 
<table cellpadding="0" cellspacing="0" border=0 width="100%">
<tr><td height="25">&nbsp;</td></tr>
<tr>
<td width="50%" align="right">
<?php
$_SESSION['admfname']= $_POST['fname'];
$_SESSION['admlname']= $_POST['lname'];
$_SESSION['admpassword']=$_POST['password'];
if (($_SESSION['admfname'] == "peter") and ($_SESSION['admlname'] == "gewant") and ($_SESSION['admpassword'] == "approvalagent"))
{
echo "<meta http-equiv='Refresh' content='0; url=admin_page.php'>";
exit; 
}
$f_name= $_POST['fname'];
$l_name= $_POST['lname'];
$pass= $_POST['password'];
if($_POST['submit'] != "Login")
{
?>
<table border="0" cellpadding="5" cellspacing="3" width="80%" class="form-noindent">
<tr><td bgColor="#ff9900">
<form method="post" action="<?php $_SERVER['PHP_SELF']?>">
<input type="hidden" name="agent" value="access">
<table border="0" width="100%">
<tr>
<td colspan="3" align="center" class="heading">Sign in with your<br> Account</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td>&nbsp;</td>
<td class="textform">First Name&nbsp;:</td>
<td class="forms" valign="top">
<input name="fname" class="cartForm" size=20 type="text"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="textform">Last Name&nbsp;:</td>
<input name="lname" class="cartForm" size=10 type="hidden">
<td class="forms" valign="top">
<input name="lname" class="cartForm" size=20 type="text"></td>
</tr>
<tr>
<td>&nbsp;</td> 
<td class="textform">Password&nbsp;:</td>
<td class="forms" valign="top">
<input class="cartForm" name="password" size=20 type="password"></td>
</tr>
<tr>
<td valign="top" colspan="3" align="center">&nbsp;&nbsp;
<input type="submit" name="submit" value="Login" class="cartForm" >
</td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
<td colspan="2" align="center"><div class="leo"><a href="forget.php">Forget Password</a></div></td>
<td align="center"><div class="leo"><a href="order.php">New user click here</a></div></td>
</tr>
</table>
</form>
</td></tr>
</table>
</td>
<td width="50%" align="center"><img src="images/online.jpg"></td>
</tr>
</table>
<br><br>
<?php }
elseif($f_name== "" or $l_name== "" or $pass== "")
{
?>
<table border="0" cellpadding="5" cellspacing="3" width="80%" class="form-noindent">
<tr><td bgcolor="#00CC99">
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<input type="hidden" name="agent" value="access">
<table border="0" width="100%">
<tr>
<td colspan="3" align="center" class="heading">Sign in with your Account</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr><td colspan="3" align="center" class="heading">Please fill all the fields</td></tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td>&nbsp;</td>
<td class="textform">First Name&nbsp;:</td>
<td class="forms" valign="top">
<input name="fname" class="cartForm" size=20 type="text"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="textform">Last Name&nbsp;:</td>
<input name="lname" class="cartForm" size=10 type="hidden">
<td class="forms" valign="top">
<input name="lname" class="cartForm" size=20 type="text"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="textform">Password&nbsp;:</td>
<td class="forms" valign="top">
<input class="cartForm" name="password" size=20 type="password"></td>
</tr>
<tr>
<td valign="top" colspan="3" align="center">&nbsp;&nbsp;
<input type="submit" name="submit" value="Login" class="cartForm" >
</td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
<td colspan="2" align="center"><div class="leo"><a href="forget.php">Forget Password</a></div></td>
<td align="center"><div class="leo"><a href="order.php">New user click here</a></div></td>
</tr>
</table>
</form>
</td></tr>
</table>
</td>
<td width="50%" align="center"><img src="images/login1.jpg" width="300" height="200"></td> 
</tr>
</table> 
<?php
}
else {
$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'] = $f_name;
$_SESSION['slname'] = $l_name;
$_SESSION['sid'] = $id;
echo "<meta http-equiv='Refresh' content='0; url=user_page.php'>";
exit;
}//if loop
}//for loop
echo "<meta http-equiv='Refresh' content='0; url=new_user.php'>";
exit;
}
?>
<tr><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td>
<table border="0" width="100%">
<tr><td align="center" class="copy">Copyright © 2006 www.bankon.us All Rights Reserved</td></tr>
</table>
</td>
</tr>
</td>
</tr>
</table>
</BODY>
</HTML>

HI,

Are you including this file? or is this php script run directly? If you're including, then look into the parent file for the problem.

Are you sure you're updating the file on your remote server, maybe the file is still the old one with the error?

What are you using to edit your php file?

Have you tried editing the file directly on your server? Eg: using a shell access, or some web based control panel (Cpanel/Ensim etc.)

Reason youre getting this error:
sessions are implemented either as cookies or via the url. In your case, cookies, and the session cookie cannot be sent. A cookie is actually a http header.
HTTP headers need to be sent before HTTP Content (PHP output).

So some http content is already being sent somewhere... even though your script looks fine.

hi pls help me

this is my main file and i m running it directly
my problem is that i m using window xp and run php & mysql in it thr it run
but whn i run this file in linux server than these problems come
so there will be any problem of that

i have send u full file
i don't know from where some http content is sent

pls help me

Try removing blank lines from your html. I got this error a while back and this was the solution.

Hi

thank u for u r suggestion i will try it
and thn i will tell u tht it works or not

bye


Try removing blank lines from your html. I got this error a while back and this was the solution.

Hi

I try wht u do but still i cann't run
this is my main file
and i m using notepad & dreamweaver for editing php

pls help me

i run this prog in my localhost thn it runs
my localhost is window xp
and whn i upload it in linux server thn the error comes

so pls help me

my boss is going 2 kill me if i cann't run this prog.
:sad: :sad: :sad: :sad: :sad: :sad: :sad: :sad: :sad: :sad: :sad:

HI,

Are you including this file? or is this php script run directly? If you're including, then look into the parent file for the problem.

Are you sure you're updating the file on your remote server, maybe the file is still the old one with the error?

What are you using to edit your php file?

Have you tried editing the file directly on your server? Eg: using a shell access, or some web based control panel (Cpanel/Ensim etc.)

Reason youre getting this error:
sessions are implemented either as cookies or via the url. In your case, cookies, and the session cookie cannot be sent. A cookie is actually a http header.
HTTP headers need to be sent before HTTP Content (PHP output).

So some http content is already being sent somewhere... even though your script looks fine.

Ok...
Try this.

Open your script in notepad. (do not use dreamweaver).
Delete everything before the <?

Make sure <? is right at the top.

Then save the script as plain text. say "file.txt"
Upload it to your sever via ftp, don't use dreamweaver.

In ftp, rename your txt file back to the php extension.

Make sure you are uploading your files as binary. This can be done with most ftp programs.
Usually, if this is a problem with the upload, then the whole file should be "bad". But it just seems that the file on your Linux server, has some text added before the <?. So it could also be the editor, which is dreamweaver, so dont use it.

This error comes when u r starting a session after any HTML tags, plz start the session at the veery top of the page

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.