This is the error

Warning: Cannot modify header information - headers already sent by (output started at /home/rejocoma/public_html/login-registor/do_login.php:9) in /home/rejocoma/public_html/login-registor/do_login.php on line 40

and this comming only on my hosting not in local machine ita unix hosting solution

can any one give me a help on this im a new in php and pleas give me a help...

Thank you.........

Recommended Answers

All 9 Replies

u must be using header() function after ur output has started...
mind it header() cant be used once you started sending some output to ur browser.. not even a single blank space...

Post up the code if u need more clarification on this

This is the error

Warning: Cannot modify header information - headers already sent by (output started at /home/rejocoma/public_html/login-registor/do_login.php:15) in /home/rejocoma/public_html/login-registor/do_login.php on line 6

and this comming only on my hosting not in local machine ita unix hosting solution

can any one give me a help on this im a new in php and pleas give me a help...

Thank you.........

This is my codes what is the wrong with this :(

<?php 
session_start();              


include("../init/db.php");
$uname=$_POST['uname'];
$pass=$_POST['pass'];

echo $uname."<br />";
echo $pass;
$res ="";


$sql = "SELECT * FROM `users` WHERE uname='$uname'";
$result = mysql_query($sql);
$row=mysql_num_rows($result);

if($row==1){

	while($info=mysql_fetch_array($result)){	
		$pa=$info['pass'];
	
		if($pass==$pa){
			echo "pssaword mach";
			$_SESSION['LOGGED']=true;
			$_SESSION['uname']=$info['uname'];
			$_SESSION['fname']=$info['fname'];
                         header("Location:../usercp.php");                    
					
			}
		else{
			echo "password not mach";
			$res ="password not mach";
			header("Location:../login.php?error=2");
			}
		}
}else{
	
	echo "username dos not mach";
	header("Location:../login.php?error=1");
	}

?>

comment the line 9,10 and 24 and it should work

As i said, u cant use header after sending output to browser(echo statements in this case)... Remove all echo statements before header or use them after it... though it wont get displayed in ur browser if u use them after header...
Cheers!

This is my codes what is the wrong with this :(

<?php 
session_start();              


include("../init/db.php");
$uname=$_POST['uname'];
$pass=$_POST['pass'];

echo $uname."<br />";
echo $pass;
$res ="";


$sql = "SELECT * FROM `users` WHERE uname='$uname'";
$result = mysql_query($sql);
$row=mysql_num_rows($result);

if($row==1){

	while($info=mysql_fetch_array($result)){	
		$pa=$info['pass'];
	
		if($pass==$pa){
			echo "pssaword mach";
			$_SESSION['LOGGED']=true;
			$_SESSION['uname']=$info['uname'];
			$_SESSION['fname']=$info['fname'];
                         header("Location:../usercp.php");                    
					
			}
		else{
			echo "password not mach";
			$res ="password not mach";
			header("Location:../login.php?error=2");
			}
		}
}else{
	
	echo "username dos not mach";
	header("Location:../login.php?error=1");
	}

?>

any of those headers are not working

yeah none will work... actually looking at your code i feel there is no need of those echo statements there... may i suggest u to remove all those echo statements. Any header after an echo statement wont work

any of those headers are not working

thank you very much ......................

Not only echo, you will get this warning if you have session_start along with header function. Use

ob_start();

as the first line of your script to turn on output buffering and

ob_end_flush();

as the last line to flush the output to the buffer.

yeah i missed that... nice info !!!

Not only echo, you will get this warning if you have session_start along with header function. Use

ob_start();

as the first line of your script to turn on output buffering and

ob_end_flush();

as the last line to flush the output to the buffer.

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.