Jump to content

Headers Sent Error


timecatcher

Recommended Posts

Hello again! This forum is becoming really helpful so im posting another error because I just can't understand why its still doing it.

 

'Warning: Cannot modify header information - headers already sent by (output started at /home/timecat/public_html/includes/navbar.inc.php:51) in /home/timecat/public_html/login.php on line 42

 

Warning: Cannot modify header information - headers already sent by (output started at /home/timecat/public_html/includes/navbar.inc.php:51) in /home/timecat/public_html/login.php on line 43'

 

Thats the error.

 

Also my cookies in login.php don't seem to want to work anymore so I can click login with whatever in the box and it will look as if I've logged in with that account money at 0 username displayed and the logged in navigation bar. This is all really annoying as its only supposed to display and error if you don't have the right credentials.

 

Hope you guys can see where im going wrong. Thanks. Heres the navbar script:

 

<?
require("connect.inc.php") ;

$sql = "SELECT * FROM user WHERE username='".addslashes(htmlspecialchars($_COOKIE['kurukouser']))."'" ;
$query = mysql_query($sql); 
if(mysql_num_rows($query) == 1){
$username = $_COOKIE['kurukouser'] ;
}
//old code
/*if(mysql_num_rows($query) == 1){
$username = $_COOKIE['kurukouser'] ;
}*/

//Use indentation!!!
//Learn the key differences between double quotes and single quotes!
if(!isset($username)) {

echo'<link rel="stylesheet" href="includes/layoutstylesheet.css" type="text/css">

<b>

<div id="nav">

<center>

<br />

<h3>Navigation</h3>

</center>

<b><a href="http://kurukolands.co.uk/register.php">Join</a></b>

<br />

<a href="http://kurukolands.co.uk/login.php">Login</a>

<br />

<br /></div></b>' ;
} 
//use indentation
else {

$query1 = mysql_query("SELECT * FROM user WHERE username = '".$username."'") ;

$fetch = mysql_fetch_array($query1) ;

$points = $fetch['points'] ;

	echo'<div id="nav"><center><br /><h3>Navigation</h3>' ;

	echo'<br />' ;

	echo'<a href="http://kurukolands.co.uk/news.php">News</a>';

	echo'<br />' ;

	echo'<a href="http://kurukolands.co.uk/companion.php">Companion</a>';

	echo'<br /><br />' ;

	echo'<a href="http://kurukolands.co.uk/logout.php">Logout</a></div>' ;

	echo'<div id="profile"> ' ;

	echo'Welcome, <a href="http://kurukolands.co.uk/profiles.php?userid='.$username.'">'.$username.'</a>.' ;

	echo'<br />' ;

	echo $points.' Ks' ;

	echo'</font></center>' ;

	echo'</div>' ;
}
?>

 

Heres the login script:

 

<?
require ("includes/connect.inc.php") ;
require("includes/navbar.inc.php") ;
echo '<link rel=\'stylesheet\' href=\'includes/layoutstylesheet.css\' type=\'text/css\'><div id=\'content\'>' ;
if(!$error && isset($_COOKIE['kurukouser']))
{
$username = $_COOKIE['kurukouser'] ;
	echo'You are already logged in '.$username.'.' ;

}else{
if($_POST['submit'] == 'Login') {
$username = addslashes(htmlspecialchars($_POST['username'])) ;
$password = md5($_POST['password']) ;
$query = mysql_query("SELECT * FROM user WHERE username ='".$username."' AND password='".$password."'") ;
if(mysql_num_rows($query) > 0) {
	$pwunerror = 'Please enter the correct username or password.' ;
	$error = 1 ;
}
if(!$username) {
	$usererror = 'Please enter a username.' ;
	$error = 1 ;
}
if(!password) {
	$passerror = 'Please enter a password.' ;
	$error = 1 ;
}
}
if(!$_POST['submit'] == 'Login') {
	echo'<form method="post" action="login.php"><br />Username: <input type="text" name="username"><br />Password: <input type="password" name="password"><br /><input type="submit" name="submit" value="Login">' ;
}
if($error == 1) {
	echo'<form method="post" action="login.php"><br />Username: <input type="text" name="username"><br />Password: <input type="password" name="password"><br /><input type="submit" name="submit" value="Login">' ;
	echo'<br />' ;
	echo $pwunerror ;
	echo'<br />' ;
	echo $usererror ;
	echo'<br />' ;
	echo $passerror ;
}
if(!$error == 1 && $_POST['submit'] == 'Login') {
$timestamp = 60*60*24*90 ;
setcookie('kurukouser',$username,time()+$timestamp) ;
setcookie('kurukopass',$password,time()+$timestamp) ;
}
}
echo '</div>' ;
?>

 

Thanks again, Timecatcher.

Link to comment
https://forums.phpfreaks.com/topic/135907-headers-sent-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.