ryanwood4 Posted February 24, 2009 Share Posted February 24, 2009 When users login they are getting this message: Warning: Cannot modify header information - headers already sent by (output started at /home/rawtees/public_html/loginpage1.php:10) in /home/rawtees/public_html/loginpage1.php on line 360 Warning: Cannot modify header information - headers already sent by (output started at /home/rawtees/public_html/loginpage1.php:10) in /home/rawtees/public_html/loginpage1.php on line 361 Warning: Cannot modify header information - headers already sent by (output started at /home/rawtees/public_html/loginpage1.php:10) in /home/rawtees/public_html/loginpage1.php on line 364 This is the code in question: 357 - // if login is ok then we add a cookie 358 - $_POST['email'] = stripslashes($_POST['email']); 359 - $hour = time() + 3600; 360 - setcookie(ID_my_site, $_POST['email'], $hour); 361 - setcookie(Key_my_site, $_POST['password'], $hour); 362 - 363 - //then redirect them to the members area 364 - header("Location:members.php"); This is the entire code: <?php // Connects to your Database mysql_connect("localhost", "rawtees", "angus4") or die(mysql_error()); mysql_select_db("rawtees_MembersDirectory") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $email = $_COOKIE['ID_my_site']; $password = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE email = '$email'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($password != $info['password']) { } else { header("Location:members.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['email'] | !$_POST['password']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE email = '".$_POST['email']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=www.rawtees.co.uk/loginpage.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['password'] = stripslashes($_POST['password']); $info['password'] = stripslashes($info['password']); //gives error if the password is wrong if ($_POST['password'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['email'] = stripslashes($_POST['email']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['email'], $hour); setcookie(Key_my_site, $_POST['password'], $hour); //then redirect them to the members area header("Location:members.php"); } } } else { // if they are not logged in ?> <center> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1><br></br></td></tr> <tr><td>Email:</td><td> <input type="text" name="email" maxlength="60"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="password" maxlength="10"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> Any help would be greatly appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/146772-solved-php-problem-error-help-please/ Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 You have output before the header call. Check that your script does not have a whitespace before the <?php (As this will cause issues). Quote Link to comment https://forums.phpfreaks.com/topic/146772-solved-php-problem-error-help-please/#findComment-770566 Share on other sites More sharing options...
PFMaBiSmAd Posted February 24, 2009 Share Posted February 24, 2009 output started at /home/rawtees/public_html/loginpage1.php:10 Something at line 10 in loginpage1.php is output to the browser that is preventing the headers from being sent. Since there is nothing at that point in the posted code, that probably means you have some HTML before the opening <?php tag. Quote Link to comment https://forums.phpfreaks.com/topic/146772-solved-php-problem-error-help-please/#findComment-770569 Share on other sites More sharing options...
ryanwood4 Posted February 24, 2009 Author Share Posted February 24, 2009 This is the entire code with the html at the beginning. <div id="wrapper" class="clearFix"> <div id="mainContent"> <?php // Connects to your Database mysql_connect("?", "?", "?") or die(mysql_error()); mysql_select_db("rawtees_MembersDirectory") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $email = $_COOKIE['ID_my_site']; $password = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE email = '$email'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($password != $info['password']) { } else { header("Location:members.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['email'] | !$_POST['password']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE email = '".$_POST['email']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=www.rawtees.co.uk/loginpage.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['password'] = stripslashes($_POST['password']); $info['password'] = stripslashes($info['password']); //gives error if the password is wrong if ($_POST['password'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['email'] = stripslashes($_POST['email']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['email'], $hour); setcookie(Key_my_site, $_POST['password'], $hour); //then redirect them to the members area header("Location:members.php"); } } } else { // if they are not logged in ?> <center> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1><br></br></td></tr> <tr><td>Email:</td><td> <input type="text" name="email" maxlength="60"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="password" maxlength="10"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/146772-solved-php-problem-error-help-please/#findComment-770602 Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 Put the html code before the <center> and after the ?> It is causing your error as that is "output" which is not allowed before a header call. Quote Link to comment https://forums.phpfreaks.com/topic/146772-solved-php-problem-error-help-please/#findComment-770613 Share on other sites More sharing options...
ryanwood4 Posted February 25, 2009 Author Share Posted February 25, 2009 Thanks, problem solved! Quote Link to comment https://forums.phpfreaks.com/topic/146772-solved-php-problem-error-help-please/#findComment-770664 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.