Jump to content

[SOLVED] Login not working?


Warptweet

Recommended Posts

I put this code in the <body> area of my page...

 

<?php

if ($_POST['username']) {

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

if ($password==NULL) {
echo "You did not supply a password.";
}

else

{

$query = mysql_query("SELECT username,password FROM warp_users WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($query);

if($data['password'] != $password) {
echo "The supplied login is incorrect";
}

else

{
$query = mysql_query("SELECT username,password,user_level,user_id FROM warp_users WHERE username = '$username'") or die(mysql_error());
$row = mysql_fetch_array($query);

   setcookie("username", "Warptweet", time()+3600, "/","", 0);

echo "You are now logged in, " . $COOKIE['username'] . "!";

}
}
}

echo "<center><h1>Login</h1>
<form action='login.php' method='POST'>
<table style='border:1px solid #000000;'>
<tr>
<td align='right'>
Username: <input type='text' size='15' maxlength='25' name='username'>
</td>
</tr>
<tr>
<td align='right'>
Password: <input type='password' size='15' maxlength='25' name='password'>
</td>
</tr>
<tr>
<td align='center'>
<input type=\"submit\" value=\"Login\">
</td>
</tr>
<tr>
<td align='center'>
<a href='register.php'>Register Here</a>
</td>
</tr>
</table>
</form>
</center>";

?>

 

I don't understand, I get this error when I try logging in:

 

Warning: Cannot modify header information - headers already sent by (output started at /home/warp/public_html/new/login.php:10) in /home/warp/public_html/new/login.php on line 66

 

LINE 66:

   setcookie("username", "Warptweet", time()+3600, "/","", 0);

 

What is wrong with my code? Can somebody please tip me in the right direction? I think there is something I may be missing, and I have no clue what.

 

Thanks,

-Warptweet

Link to comment
https://forums.phpfreaks.com/topic/70411-solved-login-not-working/
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.