hi everyone,
I have designed a web site which works fine in local server. but when i upload it on to server i get this problem, which really annoying me :@

I'm getting this warning,

Warning: Cannot modify header information - headers already sent by (output started at C:\...\...\Domain.com\login.php:6) in C:\...\...\Domain.com\login.php on line 68

in fact, i have removed all the whitespaces before and after <?php ... ?> tag.

help me to solve this issue...

Thanks

The most likely is that you "echo"-ed some output before you called header().

this ia the part of my page which gives out error at line number 6...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Salem Agamudaiyar Educational Trust</title>
<head>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="js/head_menu_foot.js" ></script>
<script type="text/javascript" src="js/mid_lay.js" ></script>

No echo comment are there...

The HTML itself is an output.
To get rid of that problem, make your login (and any other where you use header()) routine in a separate file, where is no output to browser.

Oh then what shoud i do for this?

Previous post, 2-nd line.

want to remove the 2nd line of that code?

i removed that but again getting that warning.

Not to remove... i was saying that all login code should be in a separate file, not within the the page which contains html code.

Anyway... instead of header() you can use javascript.

echo "<script type=\"text/javascript\">document.location.href='index.php';</script>";

BTW: Show all your login code...

i have replaeced like this instead of header()

is this right way?

echo "<script type="text/javascript">document.location.href='profilesearch.php'</script>"; 
// header("Location:profilesearch.php");// forwarded if login success

You forgot to backslash inner quotes (") and end the javascript line (semicolon)
echo "<script type=\"text/javascript\">document.location.href='profilesearch.php';</script>";

anyway i'm getting the same error warning, when i used this echo "<script type=\"text/javascript\">document.location.href='profilesearch.php'</script>";

That means that you have other header() calls...
Show all your login code here.

actually i set a cookie value for login page (error message) like Login Required, Invalid Credentials

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Educational Trust</title>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="js/head_menu_foot.js" ></script>
<script type="text/javascript" src="js/mid_lay.js" ></script>
<script type="text/javascript" src="js/default.js" ></script>
<link href="default.css" rel="stylesheet" type="text/css" />
<link href="login.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" >
$(document).ready(function()
{
   $("#s_m4").attr("src","images/m4_select.png");
   
   $("#s_m4").mouseover(function(){
   $("#s_m4").attr("src","images/m4_hselect.png");
   }).mouseout(function(){
   $("#s_m4").attr("src","images/m4_select.png");
   });
   
   $(".logout").css("display","none");
   
});
</script>
<body>

<div class="mainborder">
	<div id="idhead"></div>
	<div id="idmenubar"></div>
  	<div class="content_middle">
    <div></div>
  	<div class="content_left">
    	<div class="loginbox" >
	        <div class="loginbox_top"></div>
	        <div class="loginbox_middle">
                     <form name="form1" method="post" action="loginvalidation.php">
            	<div class="loginDiv">
         <div align="center" ><b>Enter Your Login Details</b></div>
               	  <table width="110" align="center" cellspacing="4" >
                        <tr><td height="5"></td></tr>
                     	<tr>
                        <td><input name="usrname" id="username" type="text" onfocus="clearTextFields('username','Member ID')" onblur="clearTextFields('username','Member ID')" value="Member ID" /></td>
                    	</tr>
                    	<tr>
                        <td><input name="passwrd" id="password" type="password" onfocus="clearTextFields('password','Password')" onblur="clearTextFields('password','Password')" value="Password" /></td>
                    	</tr>
                	</table>
                </div>
                <div align="center"><input class="UIButton_01" name="login" type="submit" value="Go" /></div>
                <div class="loginError" >
<?php
if(isset($_COOKIE["loginstatus"]))
{
	$logerr_msg="";
	if($_COOKIE["loginstatus"]==1)    //
	{
		$logerr_msg="Invalid Login Details";
	}
	if($_COOKIE["loginstatus"]==2)
	{
		$logerr_msg="Login Required";
	}
	echo $logerr_msg;
	setcookie("loginstatus", time()-30); // to destroy the cookie inadvance of time to expire
}
?></div>
                </form>
          </div>
	        <div class="loginbox_bottom"></div>
    </div>
  	</div>
	</div>
        <br/>
<br/>
<br/>
	<div id="idfoot"></div>
</div>
</body>
</html>

loginvalidation page

<?php
session_start();

$dbhost="xxxxx";                    // Host Name
$dbusername="xxxxx";                   // MySQL Username
$dbpassword="xxxx";                         // MySQL Password
$db_name="xxxx";             // Database Name
$table_name="xxxx";              // Table Name

// Connect to server and select databse.
$conn=mysql_connect($dbhost,$dbusername,$dbpassword) or die("Server Connection Failed: Connection to SERVER which you are attempting cannot be establish.");
mysql_select_db($db_name,$conn) or die("Database Selection Failed: Database which you select is not found.");

/*
//   To protect MySQL injection (more detail about MySQL injection)
$mymemberid = stripslashes($mymemberid);
$mymemberid = mysql_real_escape_string($mymemberid);
$mypassword = stripslashes($mypassword);
$mypassword = mysql_real_escape_string($mypassword);

// memberid and password from Form
$mymemberid=$_POST['usrname'];
$mypassword=$_POST['passwrd'];

$encrypted=md5($mypassword);

*/

// memberid and password from Form
$mymemberid=$_POST['usrname'];
$mypassword=md5($_POST['passwrd']);

$sql="SELECT * FROM $table_name WHERE memberid='$mymemberid' and password='$mypassword'";
$result=mysql_query($sql);

$curr_row = mysql_fetch_array($result);
$count=mysql_num_rows($result);               // mysql_num_rows will count no:of rows
if($count==1) {                               // If result matched $myusername and $mypassword, table row must be 1 row
// echo $curr_row['username'];
/* Uniqid (prefix, more_entropy)

A unique site ID can be created in PHP using the uniqid () function. This function has two parameters we can set. The first is the prefix. This is what will be appended to the beginning of each ID.
The second is more_entropy. If this is false or not specified it will return 13 characters, if it is true then 23 characters will be returned.
for example:
			$a_1 = uniqid(sometext);         //creates a unique id with the 'sometext' prefix
			$a_2 = uniqid (sometext, false);
			$a_3 = uniqid (sometext, true);  //creates a longer unique id with the 'sometext' prefix
*/
// ==================== For creating sessionid -- STARTS =====================
$uniq = uniqid ($memberid,true);    // creates a unique ID with a random number as a prefix - more secure than a static prefix
$md5_uniq = md5($uniq);             // this md5 encrypts the username from above, so its ready to be stored in your database
$_SESSION['sessionid']=$md5_uniq;   // creating a session
setcookie ("sessionerloginname", $mymemberid,time()+86400);
setcookie ("sessionername", $curr_row['username'],time()+86400);
									// echo $uniq;
									// echo $md5_uniq;
									// echo $_SESSION['sessionid'];
// ==================== For creating sessionid -- ENDS =======================
echo "<script type=\"text/javascript\">document.location.href='profilesearch.php'</script>";  
// header("Location:profilesearch.php");// forwarded if login success.
}
else {
	$logerror=1;
	setcookie("loginstatus", $logerror,time()+30); /* expire in 30sec */
echo "<script type=\"text/javascript\">document.location.href='login.php'</script>"; 
//header("Location:login.php");
}
?>

the setcookie() function is the same deal...
Try like that:

<?php
if(isset($_COOKIE["loginstatus"]))
{
	$logerr_msg="";
	if($_COOKIE["loginstatus"]==1)    //
	{
		$logerr_msg="Invalid Login Details";
	}
	if($_COOKIE["loginstatus"]==2)
	{
		$logerr_msg="Login Required";
	}
	//echo $logerr_msg;
	setcookie("loginstatus", time()-30); // to destroy the cookie inadvance of time to expire
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Educational Trust</title>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="js/head_menu_foot.js" ></script>
<script type="text/javascript" src="js/mid_lay.js" ></script>
<script type="text/javascript" src="js/default.js" ></script>
<link href="default.css" rel="stylesheet" type="text/css" />
<link href="login.css" rel="stylesheet" type="text/css" />
 
<script type="text/javascript" >
$(document).ready(function()
{
   $("#s_m4").attr("src","images/m4_select.png");
 
   $("#s_m4").mouseover(function(){
   $("#s_m4").attr("src","images/m4_hselect.png");
   }).mouseout(function(){
   $("#s_m4").attr("src","images/m4_select.png");
   });
 
   $(".logout").css("display","none");
 
});
</script>
<body>
 
<div class="mainborder">
	<div id="idhead"></div>
	<div id="idmenubar"></div>
  	<div class="content_middle">
    <div></div>
  	<div class="content_left">
    	<div class="loginbox" >
	        <div class="loginbox_top"></div>
	        <div class="loginbox_middle">
                     <form name="form1" method="post" action="loginvalidation.php">
            	<div class="loginDiv">
         <div align="center" ><b>Enter Your Login Details</b></div>
               	  <table width="110" align="center" cellspacing="4" >
                        <tr><td height="5"></td></tr>
                     	<tr>
                        <td><input name="usrname" id="username" type="text" onfocus="clearTextFields('username','Member ID')" onblur="clearTextFields('username','Member ID')" value="Member ID" /></td>
                    	</tr>
                    	<tr>
                        <td><input name="passwrd" id="password" type="password" onfocus="clearTextFields('password','Password')" onblur="clearTextFields('password','Password')" value="Password" /></td>
                    	</tr>
                	</table>
                </div>
                <div align="center"><input class="UIButton_01" name="login" type="submit" value="Go" /></div>
                <div class="loginError" > <?php echo $logerr_msg; ?>
</div>
                </form>
          </div>
	        <div class="loginbox_bottom"></div>
    </div>
  	</div>
	</div>
        <br/>
<br/>
<br/>
	<div id="idfoot"></div>
</div>
</body>
</html>
// Ho hoooo...

You done it...
I got what expected without any warnings...

Thanks a lot...

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.