steveangelis Posted August 14, 2009 Share Posted August 14, 2009 I know this is going to be a lot of code but I am going to toss it all out first: <?PHP if (isset($_COOKIE['user']) && isset($_COOKIE['pass'])) { $query2 = "SELECT * from member WHERE name='".mysql_real_escape_string($_COOKIE["user"])."' and pass='".mysql_real_escape_string($_COOKIE["pass"])."'" or die(mysql_error); $result2 = mysql_query($query2) or die("The information you entered does not match our records."); $row2=mysql_fetch_array($result2) or die(header('location:index.php?p=badcookie')); if ((isset($_COOKIE['user']) == $row2['name'])&& (isset($_COOKIE['pass']) == md5($row2['pass']))) { include('modules/console.php'); } } else { if (isset($_GET['l'])) { if ($_GET['l'] == '1') { $username2=$_POST['username']; $password2=$_POST['password']; $query = "SELECT * from member WHERE name='$username2'"; $result = mysql_query($query) or die("The information you entered does not match our records."); $row=mysql_fetch_array($result); $dbpassword = $row['pass']; $userid = $row['id']; //$mdp=$row['password']; if ($dbpassword == md5($password2)) { //authenticate user $password5=md5($password2); setcookie ("id", $userid); setcookie ("user", $username2); setcookie ("pass", $password5); mysql_query("update member set lastlogin='".gmdate("M d Y H:i:s")."' where id=".$userid) or die(" ".mysql_error()); mysql_close($linkid); //$username=$_COOKIE["user"]; include('modules/console.php'); //Header ("location: index2.php?p=status"); //test display authentication } else { echo "<center>Login Failed. <br><a href='index.php?p=cp'>Back</a></center>"; } } else { }?> <?PHP } else { //login html code here } } ?> Now I know that the headers are susposed to come BEFORE any html code, and for some reason this worked with my WAMP server, but now not on my real one. This page comes up as part of a template on my index page. This is a file called cp.php and it is loaded like index.php?p=cp and so on. Therefore with this method the headers are always loaded with the index page which caused my problem. Can anyone see a way of fixing my header problem? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 14, 2009 Share Posted August 14, 2009 Now I know that the headers are susposed to come BEFORE any output Fixed. Is error reporting turned on? Perhaps an error is being reported in production and causing premature output. I see you calling mysql_query() before making a database connection and using or die() which echoes output. Quote Link to comment Share on other sites More sharing options...
steveangelis Posted August 14, 2009 Author Share Posted August 14, 2009 I cut out some code to save some space. It connects to the DB perfectly fine and everything. The problem is I am getting a header error because the headers are being loaded after the page because of how the page loads via the template and I do not know if there is a way to get around it. The main problem is at this part: setcookie ("id", $userid); setcookie ("user", $username2); setcookie ("pass", $password5); This is where the header error is coming up. Quote Link to comment Share on other sites More sharing options...
steveangelis Posted August 14, 2009 Author Share Posted August 14, 2009 Warning: Cannot modify header information - headers already sent by (output started at /home/sf9761/public_html/ois/index.php:19) in /home/sf9761/public_html/ois/modules/cp.php on line 46 Warning: Cannot modify header information - headers already sent by (output started at /home/sf9761/public_html/ois/index.php:19) in /home/sf9761/public_html/ois/modules/cp.php on line 47 Warning: Cannot modify header information - headers already sent by (output started at /home/sf9761/public_html/ois/index.php:19) in /home/sf9761/public_html/ois/modules/cp.php on line 48 That is the errors I get which is those three lines of code from the previous post. Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted August 14, 2009 Share Posted August 14, 2009 there is a way to get around that. i think the function is like ob_flush or something. Do a google search for getting around header errors. I know it exists. I don't think it's the best solution, but it is a solution Quote Link to comment Share on other sites More sharing options...
steveangelis Posted August 14, 2009 Author Share Posted August 14, 2009 I tried it with ob_start and ob_flush but no matter where I put them I kept getting the same errors. I even tried putting them on the index page before the headers. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 14, 2009 Share Posted August 14, 2009 ob_start() and echo ob_get_clean() will fix the problem. Since you are dealing with multiple files, where you put them will make a difference. ob_start() should really be at the very beginning of execution and echo ob_get_clean() should be at the very end. Quote Link to comment Share on other sites More sharing options...
steveangelis Posted August 15, 2009 Author Share Posted August 15, 2009 That worked. Thank you. 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.