Jump to content

[SOLVED] Warning: Cannot modify header information


eaglelegend

Recommended Posts

Warning: Cannot modify header information - headers already sent by (output started at /misc/39/000/171/334/2/user/web/eaglelegend.com/header.php:2) in /misc/39/000/171/334/2/user/web/eaglelegend.com/login.php on line 11
Cant set cookie

 

HELP!, I get that when I try and log in my site, on IE... what would it be do you think? help much appreciated thanks!

(opens up login.php)

 

Ahhh yess.... there it is!

 

 

For real man, you gotta show some code not just an error.

 

We can probably tell you why you're getting the error but that's about it. Headers are already being sent somewhere in your code. You probably have some HTML or something before the header() is being called.

Sorry!

<?
include("header.php");

$username = $_POST['username'];
$password = $_POST['password'];

if($username && $password) {
$check = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `username`=\"$username\" AND `password`=\"$password\""));

if($check == 1) {
 	if(setcookie("ipets",$username,time()+(3600*24))) {
 	 	Header("Location: index.php");
 	}
 	else {
 	 	print "Cant set cookie";
 	}
}
else {
 	print "Sorry, username/password mismatch!";
}

}
else {
?>
<h2>Login</h2><p>
<form action="login.php" method="post">
Username<br>
<input type="text" name="username" size="20"><p>
Password<br>
<input type="password" name="password" size="20"><p>
<input type="submit" value=" Login "></form>
<? 
}

include("footer.php");
?>

You are trying to set a cookie in line 11 of the code above but in line 2 of header.php you have something outputting to the browser. Look at line 2 of header.php and see if you are outputting something or list the code for header.php.

 

Ray

how do I fix this? header is:

 

      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <?php include("config.php"); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<meta name="author" content="Me">
<meta name="description" content="Eagle Legend - The newest, safest and best Virtual Pet Site in the hole of Cyberspace!">
<meta name="keywords" content="eagle legend, eaglelegend, eagle, legend, pets, pet, games, game, virtual, chat, fun, prizes, play, virtual pet, kids">
<meta name="revised" content="Eagle Legend, 04/01/08">
<title>Eagle Legend</title>
<link rel="stylesheet" href="style.css" type="text/css">
<script language="JavaScript" type="text/javascript">
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=600');");
}
</script>
<link rel="shortcut icon" href="favicon.ico">
<style type="text/css">
div.c1 {text-align: center}
</style>
</head>
<body>
<div class="c1">
<table border="0" width="980" cellpadding="4" cellspacing="4" bgcolor="#000000">
<tr>
<td colspan="2"><a href="index.php"><img src="images/headers/banner.png" border="0" alt="Eagle Legend"></a></td>
</tr>
<tr>
<td width="180" valign="top" bgcolor="#04AA44">
  <? include("nav.php"); ?>
  </td>
<td width="800" valign="top" bgcolor="#70BEFF">

Quick fix, but read the sticky

<?php
ob_start();
include("header.php");

$username = $_POST['username'];
$password = $_POST['password'];

if($username && $password) {
$check = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `username`=\"$username\" AND `password`=\"$password\""));

if($check == 1) {
 	if(setcookie("ipets",$username,time()+(3600*24))) {
 	 	Header("Location: index.php");
 	}
 	else {
 	 	print "Cant set cookie";
 	}
}
else {
 	print "Sorry, username/password mismatch!";
}

}
else {
?>
<h2>Login</h2><p>
<form action="login.php" method="post">
Username<br>
<input type="text" name="username" size="20"><p>
Password<br>
<input type="password" name="password" size="20"><p>
<input type="submit" value=" Login "></form>
<? 
}

include("footer.php");
ob_endflush();
?>

<?php
$username = $_POST['username'];
$password = $_POST['password'];

if($username && $password) {
$check = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `username`=\"$username\" AND `password`=\"$password\""));

if($check == 1) {
 	if(setcookie("ipets",$username,time()+(3600*24))) {
 	 	Header("Location: index.php");
 	}
 	else {
                       include("header.php");
 	 	print "Cant set cookie";
 	}
}
else {
                include("header.php");
 	print "Sorry, username/password mismatch!";
}

}
else {
include("header.php");
?>
<h2>Login</h2><p>
<form action="login.php" method="post">
Username<br>
<input type="text" name="username" size="20"><p>
Password<br>
<input type="password" name="password" size="20"><p>
<input type="submit" value=" Login "></form>
<? 
}

include("footer.php");
?>

Thanks cooldude832,

it really works :)...

changing the topic a little bit, does anyone know how I can make it all "session" instead of cookies, without affecting my users etc.?

 

sorta mad at myself for showing u that because it ain't exactly the proper way to do things.  If a page is to redirect via a header("location: ") it should be clear of any output before the page negotiates if it needs to redirect or not.  output buffering usefulness is in running through lengthy sections to buffer the output, not to sneak around header messes.

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.