fery0098 Posted November 2, 2010 Share Posted November 2, 2010 hello i use the fallowing code for my login page but it gives me the fallowing error i was wondering what is the problem? (line 179 is the setcookie) by the way it doesn't set the cookie any help would be appreciated error: Warning: Cannot modify header information - headers already sent by (output started at /home2/sportsh9/public_html/test/login_acc.php:6) in /home2/sportsh9/public_html/test/login_acc.php on line 179 my code: <? include_once('functions.php'); function cleanQuery($string) { if(get_magic_quotes_gpc()) // prevents duplicate backslashes { $string = stripslashes($string); } $badWords = "(delete)|(update)|(union)|(insert)|(drop)|(http)|(--)"; $string = eregi_replace($badWords, "", $string); if (phpversion() >= '4.3.0') { $string = mysql_real_escape_string($string); } else { $string = mysql_escape_string($string); } return $string; } if (isset($_COOKIE['scmuser'])) { echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\">"; }else{ if ($_POST['username']) { //did they supply a password and username $username=cleanQuery($_POST['username']); $password=cleanQuery($_POST['password']); if ($password==NULL || $username==NULL) { ?> <p align="center"> <font color="#FF0000">Username or password wasn't supplied!</font><form action="login_acc.php" method="POST"> <table style="border:1px solid #FFFFFF;" width="90%" align="center"> <tr> <td align="center">Username: </td> <td align="center"> <input type="text" size="20" maxlength="25" name="username" /></td> </tr> <tr> <td align="center">Password: </td> <td align="center"> <input type="password" size="20" maxlength="25" name="password" /></td> </tr> <tr> <td align="center" colspan="2"> <input type="submit" value="Login"/> </td> </tr> <tr> <td align="center" colspan="2"> <a href="register.php">Register</a> - <a href="forgetpass.php">Forgot Your Password?</a> </td> </tr> </table> </form> <? }else{ $query = mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error()); $data = mysql_fetch_array($query); if($data['password'] != $password) { ?> <p align="center"> <font color="#FF0000">The supplied login was incorrect</font><form action="login_acc.php" method="POST"> <table style="border:1px solid #FFFFFF;" width="90%" align="center"> <tr> <td align="center">Username: </td> <td align="center"> <input type="text" size="20" maxlength="25" name="username" /></td> </tr> <tr> <td align="center">Password: </td> <td align="center"> <input type="password" size="20" maxlength="25" name="password" /></td> </tr> <tr> <td align="center" colspan="2"> <input type="submit" value="Login"/> </td> </tr> <tr> <td align="center" colspan="2"> <a href="register.php">Register</a> - <a href="forgetpass.php">Forgot Your Password?</a> </td> </tr> </table> </form> <? }else{ $query = mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error()); $row = mysql_fetch_array($query); setcookie("scmuser", "$username", time()+3600); echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\">"; } } } } ?> thank you Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 2, 2010 Share Posted November 2, 2010 The answer to your question was staring you in the face before you posted this. The very first stikied and locked post at the top of the PHP forum is titled "HEADER ERRORS - READ HERE BEFORE POSTING THEM". The answer you are looking for is there: http://www.phpfreaks.com/forums/php-coding-help/header-errors-read-here-before-posting-them/ Quote Link to comment Share on other sites More sharing options...
rwwd Posted November 2, 2010 Share Posted November 2, 2010 Bad coding practice:- <? echo "I am php code"; ?> Good coding practice:- <?php echo "I am php code"; ?> Now see what's missing from your example ;p Rw Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2010 Share Posted November 2, 2010 Given that the opening php tag is not in the left-most column, I'm going to guess you have 5 lines of HTML tags at the start of the file, that you did not post, plus the white-space we see before the opening php tag. All of that is output that cannot occur before any setcookie/header/session_start... statement. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2010 Share Posted November 2, 2010 Where are the actual To: and From: email address you are trying hosted at? Are they hosted at the sending mail server or at some other ISP? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2010 Share Posted November 2, 2010 ^^^ Wow, how did I post that in this thread? Especially since I saw it posted in the correct thread. Edit: I smell a bug in the recently turned on SEO friendly URLs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.