The Midnighter Posted January 3, 2009 Share Posted January 3, 2009 I've got some code. (duh) It keeps telling me I'm trying to send headers twice, does anyone have any reason why it might say that? The two lines in question are as follows, Warning: Cannot modify header information - headers already sent by (output started at /hdd/2/home/com/info.mooseheadbeer.com/password_protect.php3:80) in /hdd/2/home/com/info.mooseheadbeer.com/password_protect.php3 on line 79 Thats' the error, the two lines are: setcookie("verify", md5($login.'%'.$pass), $timeout, '/'); echo "Password correct."; Link to comment https://forums.phpfreaks.com/topic/139292-cookie-possibly-header-question/ Share on other sites More sharing options...
ratcateme Posted January 3, 2009 Share Posted January 3, 2009 check there are no echo's above the set cookie but that is very strange because it says it can't set a cookie on line 79 because output was on line 80 i.e. the next line which shouldn't be a problem. Scott. Link to comment https://forums.phpfreaks.com/topic/139292-cookie-possibly-header-question/#findComment-728564 Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2009 Share Posted January 3, 2009 Are you actually still using php3? It is most likely that the code is in a loop or in an include file that is being included more than once. What is the rest of the code? Just posting the two lines of code out of context does not give anyone enough information to help with the problem. Link to comment https://forums.phpfreaks.com/topic/139292-cookie-possibly-header-question/#findComment-728628 Share on other sites More sharing options...
The Midnighter Posted January 3, 2009 Author Share Posted January 3, 2009 You were right on Scott, when I removed the next line (the echo) the error went away. now I have a cookie question, I'm setting my cookie with this: if (isset($_POST['pass'])) { $sql = "SELECT * FROM Portal_administrators WHERE admin_name='" . $name . "' AND password='" . $pass . "';"; $furesult = mysql_query($sql); $valid = (mysql_fetch_row($furesult) != false); if (!$valid) { showLoginPasswordProtect("Incorrect password."); } else { setcookie("verify", md5($login.'%'.$pass), $timeout, '/'); } } And it validates like this: else { if (!isset($_COOKIE['verify'])) { showLoginPasswordProtect(""); } // check if cookie is good $found = false; foreach($LOGIN_INFORMATION as $key=>$val) { $lp = ($key) .'%'.$val; if ($_COOKIE['verify'] == md5($lp)) { $found = true; // prolong timeout if (TIMEOUT_CHECK_ACTIVITY) { setcookie("verify", md5($lp), $timeout, '/'); } break; } } if (!$found) { showLoginPasswordProtect(""); } } It seems like the cookie isnt' storing properly, what did I do wrong? Link to comment https://forums.phpfreaks.com/topic/139292-cookie-possibly-header-question/#findComment-728708 Share on other sites More sharing options...
ratcateme Posted January 3, 2009 Share Posted January 3, 2009 i don't know why it would be working but what PFMaBiSmAd said made some sense are you including the file? and is it possible for the file to be included more than once? or is that code that sets the cookie in some kind of loop? both of those would explain why you got the first error which seems very strange. Scott. Link to comment https://forums.phpfreaks.com/topic/139292-cookie-possibly-header-question/#findComment-728909 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.