Warptweet Posted September 24, 2007 Share Posted September 24, 2007 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 More sharing options...
darkfreaks Posted September 24, 2007 Share Posted September 24, 2007 try using ob_start(); at the top of the files. Link to comment https://forums.phpfreaks.com/topic/70411-solved-login-not-working/#findComment-353769 Share on other sites More sharing options...
Warptweet Posted September 24, 2007 Author Share Posted September 24, 2007 Thanks, that worked perfectly! The tutorials I read about cookies never said anything about ob_start(); :-\ Link to comment https://forums.phpfreaks.com/topic/70411-solved-login-not-working/#findComment-353771 Share on other sites More sharing options...
darkfreaks Posted September 24, 2007 Share Posted September 24, 2007 im abit more advanced than those tutorials eh? topic solved please! Link to comment https://forums.phpfreaks.com/topic/70411-solved-login-not-working/#findComment-353772 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.