Why I get ERROR: Cannot modify header information?
Posted: Sun Apr 18, 2004 5:22 am
Well, I creted a simple login script, but I Get error: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\login.php: 18) in c:\inetpub\wwwroot\login.php on line 21 The code:
please help!! I need to set cookie with username and password, if user login is successfull!! Please help me!!!
Code: Select all
<?
$username = $_POST["txtusername"];
$password = $_POST["txtpassword"];
if ($username=="" || $password=="")
{
echo "<br><br><br><br><br><center><table border='0' cellpadding='2' bgcolor='#F3F3F3'><tr><td><font face='verdana' size='1'>Please enter information in all text fields</td></tr>";
}
else
{
error_reporting(E_ALL);
$db = mysql_connect('localhost','root','q6ze32y8k1') or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$result = mysql_query("SELECT * FROM users");
while($results = mysql_fetch_array($result))
{
if ($results['username'] == $username && base64_decode($results['password']) == $password)
{
echo "You are loged in successfully<br>";
if(isset($_POST['Cookie'])) {
$set_cookie = $_POST['Cookie'];
setcookie("haveacookie",$password . "<explode_this>" . $username,time() + 360000);
}
else
{
$set_cookie = null;
}
}
}
}
?>